这样的,假设有这样的类
class Father{
int x ;
int y;
int value;
}
HashMap<Father> a = new HashMap<Father>();
___________________
Father firsrfaher = new Father(1,1,100);
a. put(firstFather);
Father otherFather = new Father(1,1,2);
if (a.contain(otherFather)) {
//equles() 和hashCode() 都已经重载
//如何现在返回true,如何拿到firstFather对象。
}
public boolean equals(Object o) {
// TODO Auto-generated method stub
if(this == o) returntrue;
if(o == null) returnfalse;
if(o.getClass() != this.getClass()) return false;
Coordinate that = (Coordinate) o;
if(this.x != that.x) return false;
if(this.y != that.y) return false;
returntrue;
}
@Override
public int hashCode() {
// TODO Auto-generated method stub
int hash = 7;
hash = hash * 31 + this.x;
hash = hash * 31 + this.y;
return hash;
}