Implement equals method using commons-lang : Class Helper « Apache Common « Java

Implement equals method using commons-lang


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


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(,, book.title).append(,;

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



Related examples in the same category

1.Implement hashCode using commons-lang
2.Use CompareToBuilder class to create compareTo method for your own class
3.Use Reflection To build toString method
4.Jakarta Commons toString Builder