According to the api, calling toString() on an Object returns
getClass().getName() + '@' + Integer.toHexString(hashCode())
Testing this
Works as expected. Would it work for any class, as long as toString() isn't overridden?
Yes, seems to:
What about an array?
In this case, we get
The hashcode of the array doesn't agree.
I could understand that if there were some intervening class in the array's inheritance tree, in which toString() were overridden, but there isn't. The showTree() method shows that Object[] is directly descendant from Object. Plus, the class of Object[], ie [Ljava.lang.Object; doesn't look like something I can look up in the api to see if it overrides toString().
How come toString() doesn't work as specified when invoked on an array?