From the book “Groovy and Grails recipes” I’m using the following code snippet:
String HelloLanguage = "def hello(language) {return \"Hello $language\"}"
However, I get a compiler error “You attempted to reference a variable in the binding or an instance variable from a static context.” because language can’t be bound. What is wrong?
I m not too familiar with Groovy I just tried your string in the GroovyConsole and I got an Exception – After escaping the dollar, it ran fine. Could it be it?
String HelloLanguage = "def hello(language) {return \"Hello \$language\"}"