Hi,
could anyone, please, explain to me what to fix in the script below? I
am getting the error message below:
Thanks,
Jochen
<<<Error>>>
: Apparent variable 'foo' was found in a static scope but doesn't
refer to a local
variable, static field or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable
from a static context.
You misspelled a classname or statically imported field. Please check the
spelling.
You attempted to use a method 'foo' but left out brackets in a place not
allowed by the grammar.
@ line 7, column 22.
demo.foo = "${foo}";
<<</Error>>>
My Java class looks like this:
<<<Java code>>>
public static void main(String[] args) {
final String SCRIPT =
"public class Demo {\n"
+ " public void run() {\n"
+ " System.out.println(\"Hello ${this.foo}\");\n"
+ " }\n"
+ " public static void main(String[] args) {\n"
+ " Demo demo = new Demo().run();\n"
+ " demo.foo = \"${foo}\";\n"
+ " }\n"
+ "}\n";
final GroovyShell gsh = new GroovyShell();
final Map<String,Object> parameters = new HashMap<>();
parameters.put("foo", "World");
final Script script = gsh.parse(SCRIPT, new Binding(parameters));
script.run();
}
<<</Java code>>>
--
The woman was born in a full-blown thunderstorm. She probably told it
to be quiet. It probably did. (Robert Jordan, Winter's heart)