Please consider the following code:-
class ABC{
public boolean equals(Object o)
{
return true;
}
}
public class HashCodePrint
{
public static void main(
String[] args)
{
HashCodePrint ore = new HashCodePrint();
ABC ore1 = new ABC();
System.out.println(ore1.equals(ore));//1
System.out.println(ore.hashCode());//2
System.out.println(ore.hashCode());//3
System.out.println(ore1.hashCode());//4
}
}
In the kathy Sierra & Bert book, under hashCode contract Its written:-
"If two objects are equal according to the equals(Object) method, then
calling the hashCode() method on each of the two objects must produce
the same integer result.". Now at 1, it shows that the object are equal. But they produce the different integer values at 3 & 4.
Please explain as I think I'm not able to understand this hashCode.