当从@CompileStatic 下的另一个闭包隐式调用闭包时,调用者会以某种方式进入递归循环。你能发现代码的问题,还是 Groovy 的问题:
import groovy.transform.CompileStatic
@CompileStatic
class Main {
static main(args) {
TestClass testclass = new TestClass()
testclass.foo()
//testclass.bar() // compile error for closure with @CompileStatic
testclass.bar.call() // compiles and works fine
}
}
@CompileStatic
class TestClass {
void foo () {
println('In foo')
bar() // inside a method -- works fine
}
Closure bar = {
println('In bar')
//baz() // What's going on here?? It compiles, but instead
// of calling baz, this recurses on itself (seemingly)
baz.call() // this works fine
}
Closure baz = {
println('In baz')
}
}
[Groovy 版本:2.4.5]
注意:这个 SO question讨论了一个类似的问题,但与之相关的 Groovy 问题说它已被修复。