final
变量的 equals()
的实现。 这样的访问可能导致 equals()
在该对象生命周期的不同时刻返回不同的结果,进而可能在使用标准集合类时导致问题。
示例:
public class Person {
private String lastName;
@Override
public boolean equals(Object obj) {
...
Person other = (Person) obj;
if (lastName == null) {
if (!lastName.equals(other.lastName)) {
return false;
...
}
}
}