Ian created GROOVY-10241:
----------------------------

             Summary: 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


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