标签:转换 对象 this java ble 建议 com equal .com
@Override
public boolean equals(Object otherObject) {
//1.检测this 与 otherObject 是否引用同一个对象
if (this == otherObject) return true;
//2.检测otherObject 是否为null, 如果为null,返回false
if (null == otherObject) return false;
//3.比较this 与 ohterObject 是否属于同一个类
if(getClass() != otherObject.getClass()) return false;
if (!(otherObject instanceof Employee)) return false;
//4. 将otherObject 转换为相应的类类型变量
Employee employee = (Employee) otherObject;
//5.域比较
if (id != employee.id) return false;
if (Double.compare(employee.salary, salary) != 0) return false;
if (name != null ? !name.equals(employee.name) : employee.name != null) return false;
return true;
}
-- 摘《java核心技术:卷一》
标签:转换 对象 this java ble 建议 com equal .com
原文地址:http://www.cnblogs.com/lyzblog/p/6013297.html