This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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: 9613
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: 9613
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!