Skip to content

Commit aaca861

Browse files
committed
finished Article 8 for Effective Java
1 parent 37ea8d5 commit aaca861

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

docs/effective-java.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,4 +881,10 @@ public boolean equals(Object o) {
881881

882882
3. **把参数转换成正确的类型**。因为转换之前进行过 instanceof 测试,所以确保会成功。
883883

884-
4.
884+
4. **对于该类中的每个“关键”域,检查参数中的域与该对象中对应的域相匹配**
885+
886+
5. **当你编写完成了 equals 方法之后,应该问自己三个问题:它是否是对称的、传递的、一致的?**
887+
888+
- **覆盖 equals 时总是要覆盖 hashCode(见第 9 条)**
889+
- **不要企图让 equals 方法过于智能**
890+
- **不要将 equals 声明中的 Object 对象替换为其他的类型**

0 commit comments

Comments
 (0)