ich diesen Fehler:Warum groovy findet nicht meinen Variable in ihrem Umfang
Apparent variable 'b' 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 'b' but left out brackets in a place not allowed by the grammar.
@ line 11, column 12.
int a = (b + 5);
^
Warum ist es nicht b als Variable zu erkennen? Ich versuche zu testen, wie Scoping in Groovy funktioniert. Ist es statisch oder dynamisch?
class practice{
static void main(String[] args)
{ int b=5;
foo(); // returns 10
bar(); // returns 10
println('Hello World');
}
//public int b = 5;
static void foo()
{
int a = (b + 5);
println(a);
}
static void bar()
{
int b = 2;
println(foo());
}
}