posted 14 years ago
When you use an object as a key in a HashMap, the object's state must not change as long as it is used as a key. If the object's state changes in a way so that the hash code of the object changes, then the HashMap will get confused and won't work properly anymore. It's safest to use only immutable objects as keys in a HashMap.
So, you cannot use a mutable object like this, for example: