【发布时间】:2014-06-20 09:23:45
【问题描述】:
这是我的代码:
class SpecialMeanings{
String prop1 = "prop1"
def closure = {
String prop1 = "inner_prop1"
println this.class.name //Prints the class name
println this.prop1
println owner.prop1
println delegate.prop1
}
}
def closure = new SpecialMeanings().closure
closure()
输出是
prop1
prop1
prop1
我希望第一行是 prop1,因为它指的是定义闭包的对象。但是,所有者(并且是默认委托人)应该参考实际的闭包。所以接下来的两行应该是 inner_prop1。他们为什么不呢?
【问题讨论】: