首页 > 其他 > 详细

重写equals()的例子:

时间:2019-08-20 18:54:13      阅读:112      评论:0      收藏:0      [点我收藏+]


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;
}

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

重写equals()的例子:

原文:https://www.cnblogs.com/liyanyan665/p/11384671.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!