?????Java?б???equals?????????????壨???
???????????? ???????[ 2012/9/17 10:13:11 ] ????????
????????2????????equals????????????hashCode?????
??????????????????????Point?????p1??p2a?????????????????????true??????????????????????????HashSet.contains()?????в???????п?????????false??????
Point p1 = new Point(1?? 2);
HashSet System.out.println(coll.contains(p2)); // ??? false (?п???) |
???????????????????????false??????????з???ture????????????????????true???????????????????????????????????????????????в????????????????????????????Point??????equals????????hashCode??
??????????????????????????HashSet??????ζ???????е??????????????????????”???? hash buckets”?С?contains?????????????????????в???????????е?????????????????????б????????????????Point???汾???????equals????????????????????????hashCode??????hashCode?????Object???????汾????????????????????????任??????p1??p2??????????????????????????????????????????????????????????????????м???????????????????в????????С?contains???????????p2?????????????е????????????????????£?p1????????????????У?????p2????????p1??????????p2??p2???????????????????У???????????£?contains?????true???
?????????Point????????????????????Υ???????Object???????hashCode?????塣
??????????????????equals(Object)???????????????????????????????hashCode??????ò???????????
????????????Java?У?hashCode??equals???????????????????????????hashCode???????????equals?????????????????????Point????????????????hashCode???????????????????塣
public class Point {
private final int x;
public Point(int x?? int y) {
public int getX() {
public int getY() {
@Override public boolean equals(Object other) {
@Override public int hashCode() { } |
?????????hashCode????????????x????????41??????????41????????????y???????????????????????????????????????С??????????????????(?????????????????????)??
????????hashCode?????????????????????Point?????????????????????????????????????????????????
????δ?????......
??????

???·???
App??С????H5?????????????????Щ??
2024/9/11 15:34:34?????????????????????????
2024/9/10 11:13:49P-One ???????????????????????????????????????
2024/9/10 10:14:12???????????????????????????
2024/9/9 18:04:26??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44