• Post Reply Bookmark Topic Watch Topic
  • New Topic

overriding toString()  RSS feed

 
Surya Bavirti
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why programmeres overriding toString() method? where it is really usefull in projects?.i have seen this a lot of times in java examples.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"toString" in one shot gives you a short description about an object !! It may print an important state of your object, which comes handy in displaying an object .

If your printing some objects , you can show some user understandable message by overriding 'toString()' method, rather than printing its hashcode values !
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!