Skip to content

Commit

Permalink
finished Article 8 for Effective Java
Browse files Browse the repository at this point in the history
  • Loading branch information
joyang1 committed Jul 23, 2019
1 parent 37ea8d5 commit aaca861
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/effective-java.md
Original file line number Diff line number Diff line change
Expand Up @@ -881,4 +881,10 @@ public boolean equals(Object o) {

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

4.
4. **对于该类中的每个“关键”域,检查参数中的域与该对象中对应的域相匹配**

5. **当你编写完成了 equals 方法之后,应该问自己三个问题:它是否是对称的、传递的、一致的?**

- **覆盖 equals 时总是要覆盖 hashCode(见第 9 条)**
- **不要企图让 equals 方法过于智能**
- **不要将 equals 声明中的 Object 对象替换为其他的类型**

0 comments on commit aaca861

Please sign in to comment.