Mam dwa zestawy:assertEquals Java ustawia
Set<Attribute> set1 = new HashSet<Attribute>(5);
Set<Attribute> set2 = new HashSet<Attribute>(5);
//add 5 attribute objects to each of them. (not necessarily the same objects)
assertEquals(set1,set2); //<--- returns false, even though
//the added attribute objects are equal
równości metoda atrybut jest przesłonięta, według moich wymagań:
public abstract class Attribute implements Serializable{
public int attribute;
public abstract boolean isNumerical();
@Override
public boolean equals(Object other){
if(!(other instanceof Attribute)){
return false;
}
Attribute otherAttribute = (Attribute)other;
return (this.attribute == otherAttribute.attribute &&
this.isNumerical() == otherAttribute.isNumerical());
}
}
podczas debugowania, metoda equals nie jest nawet nazywany!
Wszelkie pomysły?
Zobacz także: [Zastępowanie równa i hashCode Java] (http://stackoverflow.com/questions/27581) – McDowell
@McDowell: Dzięki! Wiedziałem, że jeśli hashCode zwraca różne wartości dla 2 obiektów, wtedy nie ma szansy na uzyskanie wartości true od połączenia równego. Spieszyłem się! :) – Razvan