Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0-JSR-3
-
None
Description
//demo.groovy
def c = {
def x;
println x;
}
c.setDelegate(x:'hello');
c();
The output is 'null'.
//demo2.groovy
def c = {
//def x;
println x;
}
c.setDelegate(x:'hello');
c();
the output is 'hello'.
Moreover,
class Test {
static main(args) {
def c = {
def x;
println "x:${x}"
}
c.setDelegate(x:'hello')
c()
}
}
The output is 'x:null'
We can't remove 'def x' from Test class, otherwise, there is syntax error in this class(The variable x is undefined in the current scope).