Originally posted by Ernest Friedman-Hill:
Many, many classes override hashCode(). Since you're already looking at the source for java.lang.String, I'm surprised you didn't notice that String does so.
Anyway, you're thinking much too hard here. toString() returns a String, right? And so String::toString() returns itself. Whenever you print an object, toString() is called to return a printable String. String::toString() just happens to have a handy one available already!
First question, when has Java ever give you a "reference id" when you return an reference of String class? Second question, what the heck is a "reference id"?
Henry