public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof UnitUserId))
return false;
UnitUserId castOther = (UnitUserId) other;
return ((this.getUserid() == castOther.getUserid()) || (this
.getUserid() != null
&& castOther.getUserid() != null && this.getUserid().equals(
castOther.getUserid())))
&& ((this.getUnitid() == castOther.getUnitid()) || (this
.getUnitid() != null
&& castOther.getUnitid() != null && this.getUnitid()
.equals(castOther.getUnitid())));
}
public int hashCode() {
int result = 17;
result = 37 * result
+ (getUserid() == null ? 0 : this.getUserid().hashCode());
result = 37 * result
+ (getUnitid() == null ? 0 : this.getUnitid().hashCode());
return result;
}
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof UnitUserId))
return false;
UnitUserId castOther = (UnitUserId) other;
return ((this.getUserid() == castOther.getUserid()) || (this
.getUserid() != null
&& castOther.getUserid() != null && this.getUserid().equals(
castOther.getUserid())))
&& ((this.getUnitid() == castOther.getUnitid()) || (this
.getUnitid() != null
&& castOther.getUnitid() != null && this.getUnitid()
.equals(castOther.getUnitid())));
}
public int hashCode() {
int result = 17;
result = 37 * result
+ (getUserid() == null ? 0 : this.getUserid().hashCode());
result = 37 * result
+ (getUnitid() == null ? 0 : this.getUnitid().hashCode());
return result;
}
Java对象比较与哈希码实现
本文介绍了一个Java类中equals方法与hashCode方法的具体实现方式。通过对比两个对象的Userid与Unitid属性来判断对象是否相等,并且通过特定的算法计算对象的哈希值。
43万+

被折叠的 条评论
为什么被折叠?



