Reputation: 1031
I have an Interface whose implementation is deciding at Runtime and is given a Proxy Object as its dynamic implementation. I want to retrieve the Interface which this proxy object implements to know the methods in the interface. Is there any way I can do so in Java.
Upvotes: 1
Views: 109
Reputation: 340873
Try this (using plain reflection):
Class<?>[] interfaces = proxyInstance.getClass().getInterfaces();
For the following code:
Object proxyInstance = Proxy.newProxyInstance(
getClass().getClassLoader(),
new Class<?>[] {Serializable.class},
new InvocationHandler() /**/);
It correctly return java.io.Serializable
interface.
Upvotes: 3