Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.4
-
None
-
Linux x86-64 / java 1.8.0_60
Description
Originally posted on SO here: http://stackoverflow.com/questions/32212260/in-groovy-is-it-legal-to-reference-private-member-variables-from-within-a-closur
The code below fails with java.lang.ClassCastException: Test$_doStuff_closure1 cannot be cast to Test. Interestingly, if I remove the @CompileStatic annotation or make the member variable non-private it works as expected.
class Test { private String str = "hi" @groovy.transform.CompileStatic public void doStuff() { Closure c = { println str } c() } } new Test().doStuff()
It also works when @CompileStatic is moved up to the class level
@groovy.transform.CompileStatic class Test { private String str = "hi" public void doStuff() { Closure c = { println str } c() } } new Test().doStuff()
Attachments
Issue Links
- links to