日期:2014-05-20 浏览次数:20797 次
public class Test {
public static void main(String[] args) {
Map<Point , String> map=new HashMap<Point, String>();
Point point=new Point(1);
map.put(point, "第一次");
map.put(point, "第二次");
System.out.println(map);
System.out.println(map.size());
}
}
public class Point {
private int x;
public Point(int x) {
this.x=x;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + x;
return result;
}
@Override
public boolean equals(Object obj) {
return false;
}
}
map.put(point, "第一次");
map.put(point, "第二次");
if (e.hash == hash && ((k = e.key) == key
------解决方案--------------------
key.equals(k)))
return e.value;