重写hashcode

@Override
public boolean equals(Object o) {
if(this == o) {
return true;
}

if(!(o instanceof Emp)) {
return false;
}

Emp emp = (Emp)o;

return this.id == emp.id;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
return result;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

///3
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry m = (Map.Entry) it.next();
System.out.println("key:"+m.getKey()+",value:"+m.getValue());
}
//4
public Computer(float price,String year,String time,String people) {
this.price = price;
this.year = year;
super.setRksj(time);
super.setRkczy(people);

}

posted @ 2021-11-27 11:20  Beyrl.pan  阅读(94)  评论(0编辑  收藏  举报