Currently I drilled into the JSE source code for fun. From some tutorials I found a principle two equals objects (i.e. as to object a and b a.equals(b) returns true) must have the same hashcode, on the other hand, two objects with the same hashcode are not necessarily equals
. According to the HashTable source code of Java API (http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/Hashtable.java), e.g. refer to line 254, we can almost derive equals => same hashcode
, but I still can not fully understand why two objects with the same hashcode are not necessarily equals
. Anyone can give more reasoning on this? Thanks in advance
Note! This question is more interested in why two objects with the same hash code are not necessarily equals