51,409
社区成员
发帖
与我相关
我的任务
分享
public class Test {
public static void main(String[] args) {
Map<A,Object> map = new HashMap<A, Object>();
map.put(new A(), new Object());
map.put(new A(), new Object());
System.out.println(map.size());
}
}
class A {
@Override
public boolean equals(Object obj) {
System.out.println("判断equals");
return true;
}
@Override
public int hashCode() {
System.out.println("判断hashcode");
return 1;
}
}
测试结果:
判断hashcode
判断hashcode
判断equals
1
