java如何重载equals方法实例源码介绍。
1、参数是Object类型的,将参数命名为otherObject
2、检测两个引用是否指向同一个对象
if (this == otherObject) return true;
3、如果otherObject是null,则返回false
if (otherObject == null) return false;
if (otherObject == null) return false;
4、比较两个对象是否属于同一个类
if (getClass() != otherObject.getClass()) return false;
5、进行强制转换
ClassName other = (ClassName) otherObject
6、检查父类中的数据是否相等
if (!super.equals(otherObject)) return false;
7、逐条比较本类中特有的数据是否相等