public boolean equals(Object otherObject)
{
// a quick test to see if the objects are identical
if (this == otherObject) return true;
// must return false if the explicit parameter is null
if (otherObject == null) return false;
// if the classes don't match, they can't be equal
if (getClass() != otherObject.getClass()) return false;
// 由于已经判断了getClass() != otherObject.getClass(),已经证明otherObject类与本类相同
// 那么强制转换还有什么意义?
var other = (Employee) otherObject;
// test whether the fields have identical values
return Objects.equals(name, other.name)
&& salary == other.salary && Objects.equals(hireDay, other.hireDay);
}
因为你需要使用的是Employee类的特有成员,所以要向下转型。