We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 37ea8d5 commit aaca861Copy full SHA for aaca861
docs/effective-java.md
@@ -881,4 +881,10 @@ public boolean equals(Object o) {
881
882
3. **把参数转换成正确的类型**。因为转换之前进行过 instanceof 测试,所以确保会成功。
883
884
-4.
+4. **对于该类中的每个“关键”域,检查参数中的域与该对象中对应的域相匹配**。
885
+
886
+5. **当你编写完成了 equals 方法之后,应该问自己三个问题:它是否是对称的、传递的、一致的?**。
887
888
+- **覆盖 equals 时总是要覆盖 hashCode(见第 9 条)**。
889
+- **不要企图让 equals 方法过于智能**。
890
+- **不要将 equals 声明中的 Object 对象替换为其他的类型**。
0 commit comments