当隐式调用来自@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问题表明它已被修复。