I have a question related to dynamic proxies in java.
Suppose I have an interface named Foo with the execute method and class FooImpl implements Foo .
When I create a proxy for Foo and I have something like:
Foo f = (Foo) Proxy.newProxyInstance(Foo.class.getClassLoader(), new Class[] { Foo.class }, handler);
Suppose my call handler looks like this:
public class FooHandler implements InvocationHandler { public Object invoke(Object proxy, Method method, Object[] args) { ... } }
If my call code looks something like this:
Foo proxyFoo = (Foo) Proxy.newInstance(Foo.getClass().getClassLoader(), new Class[] { Foo.class }, new FooHandler()); proxyFoo.execute();
If the proxy can intercept the above call to execute from the Foo interface, which includes FooImpl , to play? Maybe I'm looking at dynamic proxies the wrong way. I want to catch the execute call from a specific implementation of Foo , for example FooImpl . It can be done?
Many thanks
java dynamic proxy
Joeblackdev
source share