In the following code segment, why does the compiler complain about the map attribute but not other types of attributes:
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
inside a closure is supposed to refer to the instance of the enclosing class, if I understand things correctly.
Note: Groovy Version: 2.4.5
Looks like a bug in the
CompileStatic
annotation, as if you change the line to:Or
Then it works fine. I'm guessing it's due to the semantics of the
[]
map accessor.You could sumbit it as a bug and see if it can be fixed