I encountered the following code and explanation in Core Java2 ( page 97 )
The hashcode for both strings is same and the hashcode for both the
string buffers will be different from each other. The explanation is that the hashcode of the String object is based on the contents of the String . And the hashcode of the StringBuffer is basically calculated by the hashCode() function of the Object class, which uses the memory address to calculate the hash code.
I thought that the compiler will encounter two identical String literals and therefore, both Strings s and t refer to the same memory location and so their hash codes are identical.
Can someone shed more light on this ?
TIA