I noticed strange behavior with MetaClass Groovy, and I am wondering if anyone can let me know what is going on here.
This works great:
@Override
Object invokeMethod(String name, Object args) {
if(true) {
println("Should only see this once")
def impl = { Object theArgs -> println("Firing WeirdAction") }
getMetaClass()."$name" = impl
return impl(args)
}
}
However, if I remove the if statement, it throws a MissingPropertyException:
@Override
Object invokeMethod(String name, Object args) {
println("Should only see this once")
def impl = { Object theArgs -> println("Firing WeirdAction") }
getMetaClass()."$name" = impl
return impl(args)
}
Here is my class instance and call, the class is empty except for the method definition above.
IfTester sut = new IfTester()
sut.WeirdAction()
Does anyone have an idea that I don't understand here?
gt124 source
share