InvocationHandler的invoke方法的第一个参数问题
2013-06-13 16:50
393 查看
今天有同事问起,动态代理中的InvocationHandler的invoke方法的第一个参数。是代理类还是委托类(即被代理类). 其实这个参数是代理类。我们看一下生成的代理类就会明白:
就这样吧.
public interface ProxyInf { public void say(); } public class TestProxy{ public void say() { System.out.println("nothing"); } public static void main(String args[]) throws IOException{ byte[] generateProxyClass = ProxyGenerator.generateProxyClass( "ProxyImpl", new Class<?>[] { ProxyInf.class}); FileOutputStream fos = new FileOutputStream("c:\\ProxyImpl.class"); fos.write(generateProxyClass); fos.close(); } }反编译C盘下面的ProxyImpl.class类文件,你会发现:
public final class ProxyImpl extends Proxy implements ProxyInf { private static Method m3; private static Method m1; private static Method m0; private static Method m2; public ProxyImpl(InvocationHandler paramInvocationHandler) throws { super(paramInvocationHandler); } public final void say() throws { try { this.h.invoke(this, m3, null); return; } catch (RuntimeException localRuntimeException) { throw localRuntimeException; } catch (Throwable localThrowable){ } throw new UndeclaredThrowableException(localThrowable); } ... }当你调用代理类的say方时,他调用的是InvokeHandler的invoke方法,并把自个做首参传了进去。
就这样吧.
相关文章推荐
- InvocationHandler中invoke方法中的第一个参数proxy的用途
- InvocationHandler中invoke方法中的第一个参数proxy的用途
- JDK动态代理的invoke方法的第一个参数是什么
- await is a reserved word 以及将forEach方法的参数改为async函数出现的问题
- YII中CHtml::listData方法第一个参数(models)的使用
- Swagger2 (4)针对于相同url headers 参数不同映射不同的方法问题(已解决)
- Java方法中参数的传递问题总结
- [置顶] Android调用js方法传递参数自动计算问题的解决
- Flex-Jsp 中Flex和Jsp传递中文参数问题的解决方法!(Tomcat服务器)
- spring mvc Restful接口传入多参数的问题和解决方案(参数全部注入第一个变量bug)
- 回发或回调参数无效。在配置中使用 问题解放方法
- 解决angular的$http.post()提交数据时后台接收不到参数值问题的方法
- 参数一个以上的问题解决方法
- C#控制台基础 activator与invoke,利用反射调用一个类的有参数方法
- 针对@FormParam出现不区分参数大小写的问题解决方法,注意标黄部分。
- ASP.NET Core 2.0 带初始参数的中间件问题及解决方法
- Rundll32.exe原理及使用, 参数传递问题解决方法(可用于批处理中)
- jsp之间传参数接受中文有乱码问题解决方法
- LayoutInflater的inflate()方法参数问题
- 关于setTimeout 第一个参数的问题解析