[ 
https://issues.apache.org/jira/browse/GROOVY-10241?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17420664#comment-17420664
 ] 

Ian commented on GROOVY-10241:
------------------------------

Those 3 all work, of course. So this is just a weird intersection between 
groovy internals and Map implementation?

Not a bug then. Thanks for looking into it Eric.

> Class Implementing Map Can't Read Fields From Within Closures
> -------------------------------------------------------------
>
>                 Key: GROOVY-10241
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10241
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.9
>            Reporter: Ian
>            Priority: Major
>
> 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':
>  
> {noformat}
> 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(){noformat}
> {noformat}
> $ groovy map.groovy 
> TheString
> OtherString{noformat}
> 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.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to