i have following code in my class:
public class Subclass<T> extends Superclass<T> {
//...
@Override
public boolean equals(Object obj) {
if (obj instanceof Subclass) {
return str.equals(((Subclass<?>) obj).getStr());
}
if (obj instanceof Identity) {
return str.equals(((Subclass<?>) obj).getStr());
}
return false;
}
}
my superclass:
public class Superclass<T> {
@NotNull
String str;
@Override
public boolean equals(Object obj) {
if (obj instanceof Identity) {
return str.equals(((Identity<?>) obj).getStr());
}
return false;
}
@Override
public int hashCode() {
return str.hashCode();
}
and checkstyle warns me Definition of 'equals()' without corresponding definition of 'hashCode()'.
do i have to override hashcode()
in my subclass even thou i dont need it anywhere or is there a better solution to get rid of this warning?