Using "$" in Groovy

Ray picture Ray · Aug 3, 2011 · Viewed 74.2k times · Source

I see { } are used for closures, and then I believe when a $ is put in front of braces, it is simply doing a variable substitution within a string. I can't find the documentation on how the $ works in the reference ... hard to search on it unfortunately, and the Groovy String documentation is lacking in introducing this. Can you please point me to the documentation and/or explain the "$" operator in Groovy -- how all it can be used? Does Grails extend it at all beyond Groovy?

Answer

Nicolas Modrzyk picture Nicolas Modrzyk · Aug 3, 2011

In a GString (groovy string), any valid Groovy expression can be enclosed in the ${...} including method calls etc.

This is detailed in the following page.