You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2017/05/02 02:03:08 UTC
[jira] [Closed] (GROOVY-3948) Replacing method on ExpandoMetaClass
doesn't work
[ https://issues.apache.org/jira/browse/GROOVY-3948?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-3948.
-----------------------------
> Replacing method on ExpandoMetaClass doesn't work
> -------------------------------------------------
>
> Key: GROOVY-3948
> URL: https://issues.apache.org/jira/browse/GROOVY-3948
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 1.6.7
> Environment: Groovy Shell (1.6.7, JVM: 1.5.0_20)
> Reporter: Lajos Papp
> Fix For: 2.2.0
>
>
> {code}
> Expando.metaClass.foo={-> def directBar=delegate.bar()
> println "directBar=${directBar}"
> def invokedBar=delegate.invokeMethod('bar',null)
> println "invokedBar=$invokedBar"
> }
> e=new Expando()
> e.metaClass.bar={->1}
> e.foo()
> //directBar=1
> //invokedBar=1
> e.metaClass.bar={->2}
> e.foo()
> //directBar=1
> //invokedBar=2
> {code}
> for some reason delegate.bar() != delegate.invokeMethod('bar',null)
> looks like at the direct call the closure got cached ...
> if the previous example continues with:
> {code}
> x=new Expando()
> x.metaClass.bar={->3}
> e.foo()
> //directBar=2
> //invokedBar=2
> {code}
> creating the new 'x' object has side effect on the 'e' objects metaclass?
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)