equals()方法的最佳实践:
1. 参数命名为otherObject
2. 检测this和otherObject是否引用同一对象, if(this==otherObject) return true;
3. 检测otherObject是否为null,为null则返回false,if(otherObject==null) return false;
4. 比较this和otherObject是否为同一个类,若是equals()的语义在每一个子类中有改变, 就使用getClass()检测, if(this.getClass()!=otherObject.getClass()) return false; 若是全部子类都有统一的语义, 就使用instanceOf检测
5. 将otherObject转化为相应的类类型变量,ClassName other = (ClassName)otherObject
6. 对全部的域进行比较,==比较基本类型,equals比较对象,全部均匹配返回true, 若是子类从新定义了equals(),就要在其中包含调用super.equals(other).数组
Arrays.toString()能够打印数组,Arrays.deepToString()能够打印多维数组安全