Created
December 30, 2016 21:09
-
-
Save CalebWhiting/fb4e5d7582bf2d6a6449a8225f1e07ee to your computer and use it in GitHub Desktop.
Template for IntelliJ IDEA to generate toString methods with String.format
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 java.lang.String toString() { | |
return String.format(## | |
"$classname [ ## | |
#set ($i = 0) | |
#foreach ($member in $members) | |
#if ($i != 0) | |
, ## | |
#end | |
#if ($member.numeric) | |
$member.name=%d## | |
#else | |
$member.name=%s## | |
#end | |
#set ($i = $i + 1) | |
#end | |
]",## | |
#set ($i = 0) | |
#foreach ($member in $members) | |
#if ($i != 0) | |
, ## | |
#end | |
#if ($member.objectArray) | |
java.util.Arrays.toString($member.accessor) | |
#elseif ( $member.primitiveArray && $java_version >= 5) | |
java.util.Arrays.toString($member.accessor)## | |
#elseif ($member.string) | |
$member.accessor ## | |
#else | |
$member.accessor ## | |
#end | |
#set ($i = $i + 1) | |
#end | |
); | |
} |
what does "##" mean at the end of the line ?
If I remember correctly, it was so that a new line was not added after each statement because the parser would skip comments and therefore the new line too (this was 4 years ago).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what does "##" mean at the end of the line ?