public boolean equals(Object otherObject) {
if (this == otherObject)
return true;
if (otherObject == null)
return false;
if (getClass() != otherObject.getClass())
return false;
Employee other = (Employee) otherObject;
return name.equals(other.name)
&& salary == other.salary
&& hireDay.equals(other.hireDay);
}
我觉得吧。第一个if完全可以判断出来,直接加一个else 反回false不就可以了吗?为什么加后面的两个if 和一个return呢?
if (this == otherObject)
return true;
if (otherObject == null)
return false;
if (getClass() != otherObject.getClass())
return false;
Employee other = (Employee) otherObject;
return name.equals(other.name)
&& salary == other.salary
&& hireDay.equals(other.hireDay);
}
我觉得吧。第一个if完全可以判断出来,直接加一个else 反回false不就可以了吗?为什么加后面的两个if 和一个return呢?
&& salary == other.salary
&& hireDay.equals(other.hireDay); 多谢,我已经明白了分不多请多包涵