If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Castable to anything or dynamically add interface to Dynamic Proxy

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.