Hey I\'m using a HashMap
to keep track of services and service-requests on a BulletinBoard. However, I must have the hashcode and equals wrong because I\'m gett
The likeliest reason is that the objects you use as keys are mutable. So if you do something like:
map.put(anAdvert, 1);
anAdvert.spawn(); //modifies id, which affects hashcode and equals
The behaviour of the map will be unexpected.
cf Map's javadoc
Note: great care must be exercised if mutable objects are used as map keys. The behavior of a map is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is a key in the map.