Skip to content

Instantly share code, notes, and snippets.

@runeflobakk
Created August 23, 2011 10:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save runeflobakk/1164848 to your computer and use it in GitHub Desktop.
Save runeflobakk/1164848 to your computer and use it in GitHub Desktop.
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