We are writing a class which requires very complicated logic to compute equals() and hashCode(). Something along lines with:
@Getters @Setters @FieldDefaults(level=AccessLevel.PRIVATE)
public class ExtealData {
TypeEnum type;
String data;
List<ExtealData> children;
}
We do not construct these objects, they are deserialized from XML from exteal complex system. There are 20+ types and depending on type data can be ignored, or processed with children, or processed without children and comparison of data for each type of node depend on type.
We created equals() and hashCode() to reflect all those rules, but recently ran into an issue that hashCode got out of sync with equals causing equal objects to be added twice to a Set.
What is the best way to make sure equals and hashCode do not get out of sync?
