0

Ordinary Maps use the following test for equality (k1==null ? k2==null : k1.equals(k2)).) IdentityHashMap uses k1==k2. My question is that even Object's equals() method returns k1==k2. Only when the Object's equals method is overridden inside a class, does it perform content based equality comparison. So, IdentityHashMap could have used Object's equals method for doing this. Is it right ? (It probably doesn't because it extends AbstractMap which already defines equals to perform content based comparison, not reference based.)

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by daudiam
0

It probably doesn't because it extends AbstractMap which already defines equals to perform content based comparison, not reference based.

AbstractMap defines the equals method based on which Maps, extending it can be compared. It seems to me that you are confusing it with the equals() method of the 'keys' which are stored inside the Map.

Edited by stephen84s: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.