If i add this and then modify the state of the object using the setter method its hashcode will not be the same and hence the i cannot get the value using this instance as a key from the hashMap. Also the contains method of Set will return false.
How to avoid this. One solution that i know is to make it immutable
Hashcode is best when calculated from immutable data;
If you need mutable fields included in the hashCode method then you can calculate and store the hash value when the object is created and whenever you update mutable field, you must first remove it from the collection(set/map) and then add it back to the collection after updating it.