When is it desired to not implement toString() in Java?

I've always made sure that my classes implemented toString.

It provides a simple way of debugging the current state of the class when I'm debugging and when I'm logging errors, I can include it into my log messages.


Removing well-written (or even halfway decently written) toString() methods is pure insanity, IMO. Yes, I am often too lazy to write these (as often the objects don't end up having them used anyway), but they are extremely handy to have.

I really can't think of a good reason to want to get rid of these.


What harm do they do? Why remove them if you have them? I find toString() extremely useful when emitting debugging statements.

Personally, I would always err on the side of having a workable toString() method. So little work to write.

Tags:

Java

Tostring