首页 新闻 会员 周边

用HashMap发现一个蛋疼的问题,进来看看能不能解答下,谢谢啦

0
悬赏园豆:20 [待解决问题]

这样的,假设有这样的类

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;

 

}

竹蜻蜓的大雄的主页 竹蜻蜓的大雄 | 初学一级 | 园豆:182
提问于:2015-04-13 22:00
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册