Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Not A Bug
-
3.0.9
-
None
-
None
-
None
Description
If a class implements 'Map' or subclasses an implementation of 'Map' then closures can't read fields in that class. This code is in a script called 'map.groovy':
class A extends HashMap { @Override Object get(Object key) { return 'OtherString' } } class B extends A { String aa = 'TheString' def foo() { println aa Closure c = {println aa} c.call() } } new B().foo()
$ groovy map.groovy TheString OtherString
I expect to get "TheString" twice.
I see the same behavior with other implementations of 'Map' or when I implement 'Map' directly.
Curiously I was not able to get the same behavior when I created my own interface defining 'get()' and implementing that.