Last active
November 24, 2016 15:19
-
-
Save danmana/28187b2a50fc1d470633bfbc19bd9c3c to your computer and use it in GitHub Desktop.
IntelliJ HashCode template (Java 7+)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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