@Test public void testMutabilityProblem(){ User foo = new User("foo", "bar", 0); MySet<User> users = new MySetHashMap<>(); users.add(foo); assertEquals(1, users.size()); assertTrue(users.isPresent(foo)); foo.setName("changed"); assertEquals(1, users.size()); assertFalse(users.isPresent(foo)); User copy = new User("foo", "bar", 0); assertFalse(users.isPresent(copy)); User changedCopy = new User("changed", "bar", 0); assertEquals(foo, changedCopy); assertFalse(users.isPresent(changedCopy)); foo.setName("foo"); assertTrue(users.isPresent(copy)); }
public void setName(String name) { this.name = name; }
User { public void setName(String name) { this.name = name; } }
User { public void setName(String name) { this.name = name; } User(String name, String surname, int id); }
User { public void setName(String name) { this.name = name; } User(String name, String surname, int id); @Override boolean equals(Object o); @Override int hashCode(); String getName(); void setName(String name); String getSurname(); void setSurname(String surname); int getId(); void setId(int id); }
User { public void setName(String name) { this.name = name; } User(String name, String surname, int id); @Override boolean equals(Object o); @Override int hashCode(); String getName(); void setName(String name); String getSurname(); void setSurname(String surname); int getId(); void setId(int id);  }