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

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);
 }

参考资料

posted @ 2019-03-13 20:12  流星<。)#)))≦  阅读(429)  评论(0编辑  收藏  举报