I know that the hashmap keys should be immutable objects or at least have a consistent hashcode to properly retrieve its value from the Map/Set. But if I use a mutating object as key without overriding hashcode or equals, will its hashcode be consistent thought its life cycle. I have tried it to retrive hashcode of a mutating object and have found it consistent always.
Share
The contract for
hashcodestates:So there is no guarantee that the hashcode won’t change if you mutate your object. It happens that some JDK implementations might use some sort of internal address but they don’t have to so you should not rely on that.