• Post Reply Bookmark Topic Watch Topic
  • New Topic

about toString() method in K&B's book  RSS feed

 
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that book, It's said that,....


Some people affectionately refer to toString() as the "spill-your-guts method," because the most common implementions of toString() simply spit out the object's state (in other words, the current values of the important instance variables).



Could somebody explain these lines?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Overriding toString() would usually mean that you want to display some meaningful information to the user about the object using the object variables. In case you dont override it and try to print it for your custom object, it would just print something like Object@3e25a5
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's obvious & no need of explanation. But I need it on that para.
 
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Abimaran Kugathasan wrote:It's obvious & no need of explanation. But I need it on that para.


Shouldn't you thank someone on their effort instead of saying it was obvious and "no need" of it?? Isn't the paragraph self explanatory?? The toString method is generally used to display the current state of the object i.e. the values of different instance fields. Some people refer to it as "spill-your-guts"...
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry reggie rui. Thanks to All. Ankit Thanks a lot.....
 
Ranch Hand
Posts: 246
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi reggie rui,

Welcome to java ranch.

Thanks,

Naveen
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

nav katoch wrote:Hi reggie rui,
Welcome to java ranch.


Reggie registered almost 1 year ago, so congrats Reggie on your first post
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well..........
 
reggie rui
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Abimaran
I think your intention of posting the message was to get a reply. So wouldn't you 'not needing it' defeat the purpose !!
Anyway, glad to help.

@Ankit
Thanks, it's good to be back after a year long hiatus
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I asked sorry for it. Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!