重写equals 和 hashCode

本文详细解析了 BinHelper 类的实现细节,包括其继承关系、序列化标识、构造方法及 equals 和 hashCode 方法的具体实现。通过对比对象属性来判断对象是否相等,并采用特定算法计算对象的哈希值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >




import com.acer.agbs.model.MdBin;

public class BinHelper
    extends MdBin {

  
    private static final long serialVersionUID = 1L;

    public BinHelper() {
    super();
    }

    @Override
    public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    final BinHelper other = (BinHelper) obj;
    if (getAid() == null) {
        if (other.getAid() != null)
        return false;
    } else if (!getAid().equals(other.getAid()))
        return false;
    if (getCode() == null) {
        if (other.getCode() != null)
        return false;
    } else if (!getCode().equals(other.getCode()))
        return false;
    if (getAcWhBusinessPurpose().getDescription() == null) {
        if (other.getAcWhBusinessPurpose().getDescription() != null)
        return false;
    } else if (!getAcWhBusinessPurpose().getDescription().equals(getAcWhBusinessPurpose().getDescription()))
        return false;
    if (getAcTypeWhMaterial().getDescription() == null) {
        if (other.getAcTypeWhMaterial().getDescription() != null)
        return false;
    } else if (!getAcTypeWhMaterial().getDescription().equals(getAcTypeWhMaterial().getDescription()))
        return false;
    return true;
    }

    @Override
    public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((getAid() == null) ? 0 : getAid().hashCode());
    result = prime * result + ((getCode() == null) ? 0 : getCode().hashCode());
    result = prime
        * result
        + ((getAcWhBusinessPurpose().getDescription() == null) ? 0 : getAcWhBusinessPurpose().getDescription().hashCode());
    result = prime * result
        + ((getAcTypeWhMaterial().getDescription() == null) ? 0 : getAcTypeWhMaterial().getDescription().hashCode());
    return result;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值