I don't understand, why does WeakHashMap
hashes keys by their hashCode()
and identifies by equals()
?
By contract of this class, it can used to tie any instance to any other instance. From my opinion, this implies hashing and comparing by identity.
Event in the doc there is a note about confusing usage with such class as String
:
This class will work perfectly well with key objects whose equals methods are not based upon object identity, such as String instances. With such recreatable key objects, however, the automatic removal of WeakHashMap entries whose keys have been discarded may prove to be confusing.
So, is there any implementation of this class, in some collections library, where it is hashed by identity?