Код: Выделить всё
public static void main(String[] args) {
HashSet set = new HashSet();
Mapper test = new Mapper("asd", 0);
set.add(test);
System.out.println(new Mapper("asd", 0).equals(test));
System.out.println(set.contains(new Mapper("asd", 0)));
}
class Mapper {
String word;
Integer counter;
Mapper (String word, Integer counter) {
this.word = word;
this.counter = counter;
}
public boolean equals(Object o) {
if ((o instanceof Mapper) && (((Mapper)o).word == this.word)) {
return true;
}
return false;
}
}
< /code>
и результат: < /p>
true < /p>
false < /p>
< /blockquote>
из спецификаций Hashset, на этом методе я прочитал это: < /p>
Подробнее здесь: https://stackoverflow.com/questions/572 ... i-expected