IdentityHashMap

IdentityHashMap is a special Map that implements the Map interface literally, but as a matter of fact, it violates the contract the Map interface documentation defines. It does it with good reason. The implementation uses a hash table just as HashMap, but to decide the equality of the key found in the bucket comparing with the key element provided as argument to the get method it uses Object reference (== operator) and not the method equals, which is required by documentation of Map interface.

The use of this implementation is reasonable when we want to distinguish different Object instances as keys that otherwise equal to each other. Using this implementation for performance reasons is almost certainly a wrong decision. Also, note that there is no IdentityHashSet implementation in the JDK. Probably such collection is so rarely used that its existence in the JDK would cause more harm than good alluring novice programmers to misuse.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.52.188