toString() in Java

Posted by Allain Lalonde on Stack Overflow See other posts from Stack Overflow or by Allain Lalonde
Published on 2009-07-21T19:27:10Z Indexed on 2011/03/17 0:10 UTC
Read the original article Hit count: 116

Filed under:

A lead developer on my project has taken to referring to the project's toString() implementations as "pure cruft" and is looking to remove them from the code base.

I've said that doing so would mean that any clients wishing to display the objects would have to write their own code to convert the object to string, but that was answered with "yes they would".

Now specifically, the objects in this system are graphic elements like rectangles, circles, etc and the current representation is to display x, y, scale, bounds, etc...

So, where does the crowd lie?

When should you and when shouldn't you implement toString?

© Stack Overflow or respective owner

Related posts about java