public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Person)) { return false; } Person p = (Person) obj; if (this.name.equals(p.name) && this.age == p.age) { return true; } else { return false; } } public int hashCode() { // 这个方法的返回值都是通过一个公式计算的 // 此时的公式:名字的hashCode * age return this.name.hashCode() * this.age; }