How do I implement hashCode using commons-lang?

Bookmark this example!  
Category: Commons Lang, viewed: 1367 time(s).
 
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
 
import java.io.Serializable;
 
public class BookHashCodeExample implements Serializable
{
    private Long id;
    private String title;
    private String author;
 
    //~ Impelments geter/setter here
 
    public int hashCode()
    {
        return new HashCodeBuilder()
                .append(id)
                .append(title)
                .append(author)
                .toHashCode();
 
        // Or even use the simplest method using reflection
        // below.
        // return HashCodeBuilder.reflectionHashCode(this);
 
    }    
}
 
 
Can't find what you are looking for? Join our FORUMS and ask some questions!

Most Viewed Examples

Latest Code Examples

100 Top & Latest


Locations of visitors to this page
eXTReMe Tracker
visitor stats
Get Chitika Premium