java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to implement hashCode using commons-lang?

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


public class BookHashCodeExample implements Serializable
    private Long id;
    private String title;
    private String author;

    //~ Impelments geter/setter here

    public int hashCode()
        return new HashCodeBuilder()

        // Or even use the simplest method using reflection
        // below.
        // return HashCodeBuilder.reflectionHashCode(this);