Why the above code prints false?Does equal method print true only for String objects(ofcourse of same value)?
Originally posted by liborio:
For variables of object type, the "value" is taken as the reference to the object - typically, the memory address. you should not use this operators to compare the contents of objects, such as strings, because they will return true if two references refer to the same object, rather then if the two objects have an equivalent meaning.
From the RHE book
Originally posted by Ron Newman:
I don't see the mutability as a real barrier to doing this right. StringBuffer.hashCode() could just return toString().hashCode() .