[
https://issues.apache.org/jira/browse/GROOVY-3412?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Daniel Sun reassigned GROOVY-3412:
----------------------------------
Assignee: Daniel Sun
> Method Caching within MethodMissing is not working
> --------------------------------------------------
>
> Key: GROOVY-3412
> URL: https://issues.apache.org/jira/browse/GROOVY-3412
> Project: Groovy
> Issue Type: Bug
> Components: groovy-jdk
> Affects Versions: 1.6, 2.4.3
> Environment: Ubuntu Linux, JDK 1.6, Eclipse 3.4
> Reporter: James Parkin
> Assignee: Daniel Sun
> Priority: Major
>
> The following code attempts to cache a method call within the methodMissing
> method, however in groovy 1.6, when the method is called for a second time
> the cached version is not being used. This code works fine in 1.5.7.
> {code}
> class PersonAgain
> {
> def work() { "working..." }
> def plays = ['Tennis', 'VolleyBall', 'BasketBall']
> def methodMissing(String name, args)
> {
> System.out.println "methodMissing called for $name"
> def methodInList = plays.find {it == name.split('play')[1] }
> if(methodInList)
> {
> def impl = { Object[] vargs ->
> return "playing ${name.split('play')[1]}..."
> }
>
> PersonAgain.metaClass."$name" = impl
> return impl(args)
> }
> else
> {
> throw new MissingMethodException(name,
> PersonAgain.class, args)
> }
> }
> static { PersonAgain.metaClass }
> }
> jack = new PersonAgain()
> println jack.playTennis()
> println jack.playTennis()
> {code}
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)