Java??hashCode??equals????????????
???????????? ???????[ 2012/10/24 10:30:56 ] ????????
??????????????У?????????????hashCode??equals?????????????????????????????????????????д?????????????Apache Commons?????????????????
????hashCode()??equals()??????Object???У????????????java?????????????е?java?????????????????
???????hashCode()??equals()
????hashCode()?????????????????????????????????????????????????洢??HashTable???????е?λ?á??????Object???hashCode()???????????????洢????????????
??????д???????
???????????д?????????????????????????κ??????????е????????????????????Щ????????????
????????????????????????????????????Employee
public class Employee
{
private Integer id;
private String firstname;
private String lastName;
private String department;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
}
?????????Employee????????Щ??????????????getter??setter???????????????????????????employee?????Ρ?
public class EqualsTest {
public static void main(String[] args) {
Employee e1 = new Employee();
Employee e2 = new Employee();
e1.setId(100);
e2.setId(100);
//Prints false in console
System.out.println(e1.equals(e2));
}
}
??????
![](/images/ad-banner/ad-banner.png)
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11