Skip to content

Instantly share code, notes, and snippets.

@danmana
Last active November 24, 2016 15:19
Show Gist options
  • Save danmana/28187b2a50fc1d470633bfbc19bd9c3c to your computer and use it in GitHub Desktop.
Save danmana/28187b2a50fc1d470633bfbc19bd9c3c to your computer and use it in GitHub Desktop.
IntelliJ HashCode template (Java 7+)
public int hashCode() {
#if (!$superHasHashCode && $fields.size()==1)
#if($fields[0].array)
return java.util.Arrays.hashCode($fields[0].accessor);
#else
return java.util.Objects.hashCode($fields[0].accessor);
#end
#else
return java.util.Objects.hash(##
#set($i = 0)
#if($superHasHashCode)
super.hashCode() ##
#set($i = 1)
#end
#foreach($field in $fields)
#if ($i > 0)
, ##
#end
$field.accessor ##
#set($i = $i + 1)
#end
);
#end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment