I wrote a class that overrides the equals (Object) method in the Object class to compare class type objects with other objects of the class type using the values ββof the object instance.
When I put an instance of an object in HashMap as a key, and then call get (Object) on the map with a new but identical object, like a key, it returns null.
I tried passing a new identical object to the equals method and returns true, so the problem is not in my comparison code.
From what I compiled using debugging, the equals (Object) method in my object is never called.
But if you use the String key in the HashMap, and then pass a new instance with the same characters to get (Object), it successfully returns the value.
Why is this happening? What do I need to do to have HashMap test keys based on the MY equals method?
source
share