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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.