【发布时间】:2016-04-04 04:17:33
【问题描述】:
在下面的代码段中,为什么编译器报错的是map属性而不报其他类型的属性:
import groovy.transform.CompileStatic
@CompileStatic
class TestMapInClosure {
Map amap = [:]
List alist = []
Integer intval = 0
Closure doFoo = {
this.amap['one'] = 'two' // !! [Static type checking] - No such property
this.alist.push(1)
this.intval += 5
}
}
如果我理解正确的话,闭包内的this 应该是指封闭类的实例。
注意:Groovy 版本:2.4.5
【问题讨论】:
标签: groovy closures compile-static