Skip to content

Instantly share code, notes, and snippets.

@vlastikcz
Last active December 12, 2019 18:28
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vlastikcz/6a3b5c158bdb7bf6e9fd to your computer and use it in GitHub Desktop.
Save vlastikcz/6a3b5c158bdb7bf6e9fd to your computer and use it in GitHub Desktop.
IntelliJ Idea - toString() template w/ StringJoiner
public java.lang.String toString() {
return new StringJoiner(", ", "$class.name{", "}")
#set($i = 0)
#foreach($member in $members)
#if(!$member.modifierStatic)
#if($member.primitiveArray || $member.objectArray)
.add("$member.name=" + java.util.Arrays.toString($member.name))
#elseif ($member.string)
.add("$member.name='" + $member.accessor + "'")
#else
.add("$member.name=" + $member.accessor)
#end
#end
#set($i = $i + 1)
#end
.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment