重写equals()
public boolean equals(Object obj) {
if (this == obj) return true;
if(obj == null) return false;
if (!(obj instanceof User))
return false;
User other=(User)obj;
if(id!=other.id) {
return false;
}
if(age!=other.age) {
return false;
}
if(name != null && other.name != null) {
if(!name.equals(other.name)) {
return false;
}
}
if(gender != null && other.gender != null) {
if(!gender.equals(other.gender)) {
return false;
}
}
if(!birthday.equals(other.birthday)) {
return false;
}
return true;
}
###重写hashCode()
public int hashCode() {
int result;
result = getName().hashCode();
result = 29 * result + getBirthday().hashCode();
result = 29 * result + getAge();
return result;
}