Może mi ktoś pomóc, bo nie ogarniam co znaczy odpowiednio? Pliiiiis
https://ibb.co/SXTJN5S
0
4
Możesz to zrobić w ten sposób:
public class Tag {
private String text;
public Tag(String text) {
this.text = text;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Tag tag = (Tag) o;
return Objects.equals(text, tag.text);
}
@Override
public int hashCode() {
return Objects.hash(text);
}
}
(Implementując metody equals i hashCode)
8
albo tak, krócej i pewniej:
public class Tag {
public Tag(String text) {
System.out.println("Dobra implementacja"); System.exit(0);
}
@Override
public boolean equals(Object o) {
return false;
}
@Override
public int hashCode() {
return 1;
}
}
EDIT:
W zasadzie to metody hasCode
i equals
można z tej implementacji wyciąć.
0
dzięęęęękuję