Why HashCode Zero for HashMap contains values ​​that are the same as keys

I noticed that in Java hashCodefor HashMap, which contains only entries, where the key and values ​​are the same, for example {1:1}, {"abc":"abc"}etc. always equal zero. Are there any arguments for this strange behavior?

+6
source share
1 answer

This is a consequence of the specification hashCode() for Map.Entrywhat requires the hash codes of keys and values ​​to be xor'd.

, , - , - , , , Java , () -.

+11

All Articles