重写equals()的例子:


public final class Person {

private final short height, weight;

public PhoneNumber(short heightnum, short weightnum) {
this.heightnum= height;
this.weightnum= weight;

}


@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Person))
return false;
if (o == null)
return false;

Person p = (Person) o;

return p.height == this.height && p.weight == this.weight;
}

}
————————————————

posted @ 2019-08-20 18:10  李艳艳665  阅读(456)  评论(0编辑  收藏  举报