Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
equals() and hashCode() template for Eclipse. It uses EqualsBuilder and HashCodeBuilder in Apache Commons Lang.
${e:import(org.apache.commons.lang3.builder.EqualsBuilder)}
${h:import(org.apache.commons.lang3.builder.HashCodeBuilder)}
@Override
public boolean equals(Object object) {
if (object instanceof ${enclosing_type}) {
${enclosing_type} another = (${enclosing_type}) object;
return new EqualsBuilder().append(${replaceWithFieldName}, another.${replaceWithFieldName}).isEquals();
}
return false;
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(${replaceWithFieldName}).toHashCode();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment