20190313 org.apache.commons.lang3.builder.EqualsBuilder的两种典型用法

时间:2021-06-01 16:01:36

org.apache.commons.lang3.builder.EqualsBuilder的两种典型用法

 public boolean equals(Object obj) {
if (obj == null) { return false; }
if (obj == this) { return true; }
if (obj.getClass() != getClass()) {
return false;
}
MyClass rhs = (MyClass) obj;
return new EqualsBuilder()
.appendSuper(super.equals(obj))
.append(field1, rhs.field1)
.append(field2, rhs.field2)
.append(field3, rhs.field3)
.isEquals();
}
 public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}

参考资料