Variable fields of objects in Java collections
I correctly assume that if you have a field contained in the Java collection & (or as a key in the map about the thing), any field used to determine the identity or relationship (through hashcode(), equals(), compareto(), etc.) cannot be changed without causing unspecified behavior collection operations? (Editor: mentioned in this other question)
(in other words, these fields should be immutable, or you should ask the object to be deleted from the collection, changed, and reinserted.)
The reason I asked is that I am reading the hibernate annotations reference guide. There is an example. There is a HashSet & Toy > but the field name and sequence of the toy class are variable and are also used for hashcode() calculation... A red flag is in my mind. I just want to make sure I understand its meaning
Solution
Javadoc of collection
This simply means that you can use mutable objects in a collection or even change them You just need to make sure that changes do not affect how set finds items For HashSet, this does not require changing the field used to calculate hashcode()