Implement equals method using commons-lang : equals « Class Definition « Java Tutorial






import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;

import java.io.Serializable;

public class Main implements Serializable {
  private Long id;

  private String title;

  private String author;

  public boolean equals(Object object) {
    if (!(object instanceof Main)) {
      return false;
    }

    if (object == this) {
      return true;
    }

    Main book = (Main) object;
    return new EqualsBuilder().append(this.id, book.id).append(this.title, book.title).append(
        this.author, book.author).isEquals();

    // return EqualsBuilder.reflectionEquals(this, book);

  }
}








5.19.equals
5.19.1.Comparing Objects
5.19.2.Implement equals method using commons-lang
5.19.3.Use CompareToBuilder class to create compareTo method for your own class
5.19.4.Define your own equals method