日期:2014-05-20 浏览次数:20700 次
public class Person{ private String ID; private String name; private String address; public String getID() { return ID; } public void setID(String ID) { this.ID = ID; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getTelephone() { return telephone; } public void setTelephone(String telephone) { this.telephone = telephone; } private String telephone; public Person(){} public Person(String ID, String name, String address, String telephone) { this.ID = ID; this.name = name; this.address = address; this.telephone = telephone; } @Override /** * 仅仅是按照ID比较是否是同一个Person */ public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Person)) return false; Person person = (Person) o; if (ID != null ? !ID.equals(person.ID) : person.ID != null) return false; return true; } @Override public int hashCode() { int result = ID != null ? ID.hashCode() : 0; // result = 31 * result + (name != null ? name.hashCode() : 0); // result = 31 * result + (address != null ? address.hashCode() : 0); // result = 31 * result + (telephone != null ? telephone.hashCode() : 0); return result; } @Override public String toString() { return "Person{" + "ID='" + ID + '\'' + ", name='" + name + '\'' + ", address='" + address + '\'' + ", telephone='" + telephone + '\'' + '}'; } }