Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #11845
| From | Sebastian <sebastian@undisclosed.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Dynamic method invocation on Proxy object? |
| Date | 2012-02-08 09:19 +0100 |
| Organization | albasani.net |
| Message-ID | <jgtb77$hsu$1@news.albasani.net> (permalink) |
How can I dynamically invoke a method on a Proxy, where the method
belongs to one of the proxied interfaces?
Normally (i. e. in the non-proxy case), one would do something like this:
protected Object invokeDelegated( Method m, Object[] args,
Object delegate ) throws Exception
{
// m is a method from an interface that is not implemented by delegate
// find the corresponding method in delegate interface and invoke
Class<?>[] parameterTypes = new Class[args.length];
for( int i = 0; i < args.length; i++ ) {
parameterTypes[i] = args[i].getClass();
}
Method meth = delegate.getClass().getMethod( m.getName(),
parameterTypes );
return meth.invoke( delegate, args );
}
However, when delegate is itself a proxy, then delegate.getClass() will
give me Proxy, which is not what I'm looking for. How can I dynamically
invoke the methods in the proxied interfaces?
-- Sebastian
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
Dynamic method invocation on Proxy object? Sebastian <sebastian@undisclosed.invalid> - 2012-02-08 09:19 +0100
Re: Dynamic method invocation on Proxy object? Steven Simpson <ss@domain.invalid> - 2012-02-08 10:34 +0000
Re: Dynamic method invocation on Proxy object? Sebastian <sebastian@undisclosed.invalid> - 2012-02-08 15:16 +0100
csiph-web