Skip to content

Instantly share code, notes, and snippets.

@ppareit
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save ppareit/3f85303b996091a44cb6 to your computer and use it in GitHub Desktop.

Select an option

Save ppareit/3f85303b996091a44cb6 to your computer and use it in GitHub Desktop.
Making StringBuilder usable from Xtend
package ppareit.util
// Add following import to any file thats wants to use StringBuilder
import static extension ppareit.util.StringBuilderUtil.*
class StringBuilderUtil {
/*
* Make += work correctly on StringBuilder objects.
*/
static def <T> +=(StringBuilder builder, T t) {
builder.append(t)
}
/*
* Example usage:
*/
static def main(String [] args) {
val msg = new StringBuilder()
msg += "Some text "
msg += "gets added"
System.out.println(msg.toString())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment