How do I get the underlying type of a proxy object in java?

前端 未结 7 1132
旧时难觅i
旧时难觅i 2020-12-09 02:05

I\'d like to access the classname of the underlying class which is an instance of java.lang.reflect.Proxy.

Is this possible?

7条回答
  •  孤城傲影
    2020-12-09 02:50

    You can use the following code for retrieve the info (ArrayUtils is from Apache commons lang) about invocation handler and the interfaces of the current proxy:

    String.format("[ProxyInvocationHandler: %s, Interfaces: %s]", 
         Proxy.getInvocationHandler(proxy).getClass().getSimpleName(), 
         ArrayUtils.toString(proxy.getClass().getInterfaces()));
    

    Example result:

    [ProxyInvocationHandler: ExecuteProxyChain, Interfaces: {interface com.example.api.CustomerApi}]}
    

提交回复
热议问题