Instantly share code, notes, and snippets.

Embed
What would you like to do?
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