Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mathifonseca/23ed9d4a93a13400336b to your computer and use it in GitHub Desktop.
Save mathifonseca/23ed9d4a93a13400336b to your computer and use it in GitHub Desktop.
GRAILS - String and variable contatenation

This seems pretty stupid, but it can happen to anyone.

This, of course, works:

boolean something = true
prinltn "The value of something is: " + something

But, this, strangely (at first) DOES NOT work:

def something = true
prinltn something + ", is the value of something"

If you notice, it fails with: MissingMethodException: No signature of method: java.lang.Boolean.plus()

That's because the + in Groovy calls the plus() method on the first item, and only numbers and strings know that you want to concatenate.

So, you have two options. One is to call the toString() method on the first item and the other is to use GStrings like this:

def something = true
prinltn "${something}, is the value of something"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment