I have to override hashCode method in my class but i have this error:
cannot find symbol: symbol: variable Objects
Also, how can i add string inventor comparison in equals my code :
public abstract class ThingMadeByHuman {
protected String inventor;
protected int yearOfInvention;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o != null || getClass() != o.getClass()) {
return false;
}
ThingMadeByHuman thingMadeByHuman = (ThingMadeByHuman) o;
return Integer.compare(thingMadeByHuman.yearOfInvention, yearOfInvention) == 0;
}
@Override
public String toString() {
return "ThingMadeByHuman: inventor:" + this.inventor + " yearOfInvention:" + this.yearOfInvention;
}
@Override
public int hashCode() {
return Objects.hash(yearOfInvention) + super.hashCode();
}
public ThingMadeByHuman(String inventor, int yearOfInvention) {
this.yearOfInvention = yearOfInvention;
this.inventor = inventor;
}
}