I've noticed some strange behavior with the Groovy MetaClass and I'm wondering if anyone can give me a clue to what's happening here.
This works fine:
@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 take off 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's my class instantiation and call, the class is empty except for the above method definition.
IfTester sut = new IfTester()
sut.WeirdAction()
Anyone have an idea what I'm misunderstanding here?