其他分享
首页 > 其他分享> > 比较两个对象中全部属性值是否相等

比较两个对象中全部属性值是否相等

作者:互联网

重写Bean_Topology的equals方法和hashcode方法

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
		
    if (obj == null || getClass() != obj.getClass()) {
        return false;
     }

    Bean_Topology topology = (Bean_Topology) obj;
    if (topology_pk == null) {
        if (topology.topology_pk != null) {
            return false;
        } 
    }else if (!topology_pk.equals(topology.topology_pk)) {
        return false;	
    }
        
    if (topology_id == null) {
        if (topology.topology_id != null) {
            return false;
        } 
    }else if (!topology_id.equals(topology.topology_id)) {
        return false;	
    }
        
        return true;
    }
	
    @Override
    public int hashCode() {
        return  topology_pk.hashCode()+topology_id.hashCode();
    }

标签:相等,return,属性,对象,pk,false,null,id,topology
来源: https://blog.csdn.net/qq_18671415/article/details/120597514