Using the Groovy package naming convention, I can intercept the calls to the Groovy method for the Java method as follows:
package groovy.runtime.metaclass.org.myGang.myPackage class FooMetaClass extends groovy.lang.DelegatingMetaClass { FooMetaClass(MetaClass delegate) { super(delegate); } public Object getProperty(Object a, String key) { return a.someMethod(key) } }
This works fine if I really create an object of class Foo:
def myFoo = new Foo() def fooProperty = myFoo.bar // metaclass invokes myFoo.someMethod("bar")
However, what if Foo is an interface and I want to intercept method calls for any implementation?
def myFoo = FooFactory.create()
Is there a way to achieve this without having a MetaClass delegation for every known interface implementation?
source share