如何从动态代理中解包原始对象 [英] How to unwrap the original object from a dynamic proxy
问题描述
解开动态代理以检索下方原始对象的最佳方法是什么?
动态代理已使用 java.lang.reflect.Proxy.newProxyInstance()
what's the best approach to unwrap a dynamic proxy to retrieve the original object beneath?
The dynamic proxy has been created using java.lang.reflect.Proxy.newProxyInstance()
创建谢谢。
推荐答案
每个代理都有 InvocationHandler
。只有 InvocationHandler
知道代理所依赖的对象(,如果有的话)。如果你控制代理的创建,那么你可以提供你自己的 InvocationHandler
,它将具有你想要的额外功能(即能够公开底层对象。)如果你不这样做,那我恐怕你运气不好。
Each proxy has an InvocationHandler
associated with it. Only the InvocationHandler
knows which object (if any) underlies the proxy. If you control the creation of the proxy, then you can supply your own InvocationHandler
that will have the extra functionality that you desire (i.e. will be able to disclose the underlying object.) If you don't, then I am afraid you're out of luck.
这篇关于如何从动态代理中解包原始对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!