Matthew Brown wrote:Using HashMap, it's the keys that are compared, not the values. It's quite happy to have lots of entries with the same value, as long as the keys are unique. And you're using a HashMap<Integer, HashCodeTest_HashMap>.
So in your second code the HashMap doesn't care about the equals() and hashCode() methods of HashCodeTest_HashMap, as your keys are all Integers.