Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.6
-
Component/s: groovy-jdk
-
Labels:None
-
Environment:Ubuntu Linux, JDK 1.6, Eclipse 3.4
-
Number of attachments :
Description
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.
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()