Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #11850
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Steven Simpson <ss@domain.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Dynamic method invocation on Proxy object? |
| Date | Wed, 08 Feb 2012 10:34:25 +0000 |
| Organization | Aioe.org NNTP Server |
| Lines | 44 |
| Message-ID | <hmv909-bic.ln1@news.simpsonst.f2s.com> (permalink) |
| References | <jgtb77$hsu$1@news.albasani.net> |
| NNTP-Posting-Host | plN2UNIo1pPS/8F6tNJbkg.user.speranza.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-15; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111229 Thunderbird/9.0 |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11850 |
Show key headers only | View raw
On 08/02/12 08:19, Sebastian wrote:
> However, when delegate is itself a proxy, then delegate.getClass()
> will give me Proxy,
Are you sure? I get $Proxy0 from this:
import java.lang.reflect.*;
public class GetProxyClass {
public static void main(String[] args) throws Exception {
ClassLoader classLoader =
ClassLoader.getSystemClassLoader();
InvocationHandler behaviour = new InvocationHandler() {
public Object invoke(Object proxy, Method method,
Object[] args) {
System.out.println("Called " + method);
return null;
}
};
Object proxy =
Proxy.newProxyInstance(classLoader,
new Class<?>[] { Runnable.class },
behaviour);
Class<?> proxyClass = proxy.getClass();
System.out.println("Proxy class is: " + proxyClass);
Method m = proxyClass.getMethod("run", new Class<?>[0]);
((Runnable) proxy).run();
m.invoke(proxy);
}
}
Output:
Proxy class is: class $Proxy0
Called public abstract void java.lang.Runnable.run()
Called public abstract void java.lang.Runnable.run()
It also demonstrates a method on the implemented interface being looked
up and invoked.
--
ss at comp dot lancs dot ac dot uk
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | 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