This week's book giveaway is in the Agile and Other Processes forum. We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line! See this thread for details.
here I am having two String Obect . "s1" is not pointing to the address that "s2" is refering to and vice versa.
I know that hashcode gives the memory address of the object.
then why it gives same hashcode for object "s1" and "s2" and not for class(ArrayMap) object ?
please let me know the real difference.
following is code snippet.
A small leak can sink a Gigantic ship.>
The default hashCode() method gives the memory address. But plenty of classes override hashCode(). In particular, any class that overrides equals() should also override hashCode() to be consistent (if two objects are 'equal', they should have the same hash code, otherwise it will break the algorithms used in classes like HashMap).
String is a good example of this. String has overridden equals() so that two String objects are equal if they have the same string value. So it also overrides hashCode() as well.
Look at the documentation of hashCode() in the Object class for full details about the contract hashCode() ought to follow.