1
我得到这个错误:为什么常规没有找到我的变量在其范围内
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);
^
为什么没有承认B中的变量?我正在尝试测试Groovy中的范围工作方式。它是静态的还是动态的?
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());
}
}