Код: Выделить всё
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, в этом методе I прочитал это: < /p>
antified this specified this vitions this vitions this specified. Более формально возвращает true, если и только если этот набор содержит элемент E, такой, что (o == null? E == null: o.equals (e)). Или ...?>
Подробнее здесь: https://stackoverflow.com/questions/572 ... ed-from-it