|
-
March 13th, 2009, 03:19 PM
#1
Castable to anything or dynamically add interface to Dynamic Proxy
I have your typical creation of a DynamicProxy:
MyInterface handler = (Gra) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { MyInterface.class }, handler);
After this, now I want handler to be castable to a different interface, let's say Iface2.
If I try to do so:
Iface2 try = (Iface2)handler;
it will throw a class cast exception. I know I could create a new proxy, but that won't work for me because I may already have places in the code that have a reference to this specific instance.
So, either I want to be able to magically make the handler instance castable to a new type, or... is there some way in the initial creation of handler that I could make it castable to any anything to begin with?
I want a proxy that is castable to anything (or that I can add things at runtime)--any calls to it go to InvocationHandler.invoke anyway, so... casting doesn't matter.
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|