Changing the elements in a set changes the 'equals' semantics
Imagine that we have this piece of code. public class HashAddAfter { private class A { public int value; public A(int value) { this.value = value; } public void setValue(int value) { this.value = value; } // Code for hashCode()... // Code for equals()... } Set<A> list1 = new HashSet<A>(); Set<A> list2 = new HashSet<A>(); public static void main(String[] args) { HashAddAfter x = new HashAddAfter(); A e1 = x.new A(1); A e2 = x.new A(1); x.list1.add(e1); x.list2.add(e2); System.out.println(x.list1.equals(x.list2)); // true e1.setValue(4); e2.setValue(4); System.out.println(x.list1.equals(x.list2)