简体   繁体   English

为什么InvocationHandler中的方法invoke()有一个参数Object proxy?

[英]why does the method invoke() in InvocationHandler have an parameter Object proxy?

When you r checking out that the method invoke(Object proxy, Method method, Object[] args) declaration & the doc statement,you will find that the input parameter proxy 当你检查出方法调用(Object proxy,Method method,Object [] args)声明和doc语句时,你会发现输入参数代理

proxy - the proxy instance that the method was invoked on proxy - 调用该方法的代理实例

when I am doing a test on java dynamic proxy,I find this proxy is produced by vm.So I do want to know why the method invoke has this param,which is surely nothing except that is just an object ($proxy0 )but don't have the actual action for our usage? 当我在java动态代理上进行测试时,我发现这个代理是由vm生成的。所以我想知道为什么方法调用有这个参数,除了那只是一个对象($ proxy0)之外什么都没有对我们的使用有实际行动吗?

This very useful if you have single invocation handle for multiple proxy objects. 如果您有多个代理对象的单个调用句柄,这非常有用。 So you can use hash map to store proxy states information. 因此,您可以使用哈希映射来存储代理状态信息。 For example - Mokito test framework store proxy invocation history. 例如 - Mokito测试框架存储代理调用历史记录。

if you are chinese ,you can read this article http://rejoy.iteye.com/blog/1627405 如果你是中国人,你可以阅读这篇文章http://rejoy.iteye.com/blog/1627405

he makes a decompliation of $proxy0.class, you should know that $proxy0 extends Proxy 他对$ proxy0.class进行了解压缩,你应该知道$ proxy0扩展了Proxy

public final class $Proxy0 extends Proxy  
    implements UserService 

and there is a function in $proxy0: $ proxy0中有一个函数:

public final void add()  
    {  
        try  
        {  
            //the h(invocationhandler) is in Proxy class,so we need pass this $proxy0 instance to super ,so the super(Proxy) can invoke($proxy0,method,args)
            super.h.invoke(this, m3, null);  
            return;  
        }  
        catch(Error _ex) { }  
        catch(Throwable throwable)  
        {  
            throw new UndeclaredThrowableException(throwable);  
        }  
    }  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用的java.lang.reflect.InvocationHandler的方法参数列表中的“代理”对象代表什么? - What does “proxy” object from invoke's method parameters list of java.lang.reflect.InvocationHandler represent? 为什么jdk动态代理在调试每一步模式时调用InvocationHandler.invoke“toString”方法 - Why jdk dynamic proxy invoke InvocationHandler.invoke “toString” method when debug every step over mode 为什么我可以在InvocationHandler的invoke()方法中调用proxy.getClass()? - Why can I call proxy.getClass() inside InvocationHandler's invoke() method? 了解java.lang.reflect.InvocationHandler的invoke方法的“代理”参数 - Understanding “proxy” arguments of the invoke method of java.lang.reflect.InvocationHandler 使用InvocationHandler在代理类中调用NoClassDefFound并调用 - NoClassDefFound in proxy class using InvocationHandler and invoke 对我的代理类中的每个方法执行InvocationHandler调用方法 - Execute InvocationHandler invoke method for each method at my proxied class 通过 Proxy、InvocationHandler 和自定义 Annotations 实现参数验证 - Implement parameter validation through Proxy, InvocationHandler and custom Annotations Java代理->为什么代理对象具有与原始对象相同的hashCode - Java Proxy -> Why does have proxy object same hashCode like original object 为什么可以在类型参数上调用静态方法? - Why is it possible to invoke a static method on a type parameter? 为什么Javassist ProxyFactory的create方法没有基于args参数调用正确的构造函数? - Why the create method of Javassist ProxyFactory does not invoke the right constructor based on the args parameter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM