from p.46 "Effective Java" Joshua Bloch. Item 9: ALways override hashCode when you override equals
- Some class PhoneNumber overrides equals() and doesn't override hashCode()
- "two instances are involved: one is used for insertion into the HashMap, and a second, equal, instance is used for (attempted) retrieval." ... "... Even if the two instances happen to hash to the same bucket, the get method will almost certainly return null , as HashMap has an optimization that caches the hash code associated with each entry and doesn't bother checking for object equality if the hash codes doesn't match."
The questions is - why 'get' will return 'null' if "the two instances happen to hash to the same bucket"?
what is the role (in not getting the right instance) of the HashMap optimization "that cashes..."?
Just for the case - "the two instances happen to hash to the same bucket"- what if HashMap bothers about "object equality if the hash codes doesn't match"?