Object.toString()
JavaDoc says:
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object.
Still, so many of the standard java classes like Collections
(Sets, Lists etc) that could have a very useful toString()
methods, don't bother implementing it. Is there a reason for this stupidity?
Or hey, would you like a hex string instead? :)
EDIT: Oops, this was my failure in using my IDE. I followed the interface instead of the implementation and that took me for some reason straight to Object.toString()
.
UPD:
If you mean Collection
classes, so answer will be:
this is not exactly like this. Many of the Collection
classes override this method; for example, the AbstractCollection
class, which has its own toString
implementation - common for all inherited classes.
If you mean Collection[s]
, then this class has a private constructor and can not be instantiated; so a special toString
method is pointless.
If You are talking about Collections class, it is utility class, it is not necessary to have toString() method overridden. Generally in case of utility classes we make constructors private and provide static methods.
Also check you can not create an object of Collections class becuase it's constructor is made private. Check java.util.Collections
source, Line number 56
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With