I am having this problem with a LinkedHashSet and its contains method. Let me summarize it to you.
I have this class C1 with 4 String attributes, its respective getters and setters as well as equals(), and hashCode() methods as given by default by eclipse.
Then I have another class C2 that has 1 attribute of type LinkedHashSet with the getSet() method for accessing it.
When I create 1 instance of a C1 class (say object c1) and add it to an instance c2 of class C2, everything is fine... I do:
C1 c1 = new C1("a", "b", "c", "d");
C2 c2 = new C2();
c2.getSet().add(c1);
Now if I set a different value to the first attribute of c1, with the appropriate set method, and then I try to check if c2.getSet() contains element c1... but it always returns false. But the hashcode of the object changed and the one within the set is the same, and apparently, the equals test in the contains method is failing...
Does anyone understand what is happening here? What can be wrong? Equals and HashCode()?
Thanks in advance, cheers