1

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.

Abhishek
  • 1,031
  • 4
  • 16
  • 25

1 Answers1

3

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.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674