Equals:
Object 类中的 equals 方法用于检测一个对象是否等于另一个对象。
实现:
| public class MyClass {
 private Integer field1;
 
 private String field2;
 
 @Override
 public boolean equals(Object otherObject) {
 
 
 if (this == otherObject) {
 return true;
 }
 
 
 if (otherObject == null) {
 return false;
 }
 
 
 if (!(otherObject instanceof MyClass)) {
 return false;
 }
 
 
 MyClass other = (MyClass) otherObject;
 return this.field1.equals(other.field1)
 && this.field2.equals(other.field2);
 }
 }
 
 |