美文网首页
代码模型-对象比较

代码模型-对象比较

作者: 河神_6961 | 来源:发表于2017-08-07 23:28 被阅读0次

public boolean compare (Person per) {

if(per == this) {

return true ;

}

if(per == null) {

return false ;

}

if(this.name.equals(per.name) && this.age == age) {

return true ;

}

return false ;

}

总结:对象比较是一个类本身所具备的功能,比较的时候最核心的问题:①比较地址、②判断是否为空、③判断各个属性。(①和②可以交换)

相关文章

网友评论

      本文标题:代码模型-对象比较

      本文链接:https://www.haomeiwen.com/subject/xkezlxtx.html