737
说明
1、JDK动态代理不需要实现界面,只有目标对象需要实现界面。
2、基于接口的动态代理需要使用JDK中的API,在JVM内存中动态构建Proxy对象。
3、需要使用java.lang.reflect.Proxy和newProxyInstance方法,但该方法需要接收三个参数。
实例
publicclassBusinessAgentimplementsSell{ privateVendormVendor; publicBusinessAgent(Vendorvendor){ this.mVendor=vendor; publicvoidsell(){ System.out.println("before"); mVendor.sell(); System.out.println("after"); publicvoidad(){ System.out.println("before"); mVendor.ad(); System.out.println("after");
以上就是java动态代理的特点,希望对大家有所帮助。更多Java学习指路:Java基础
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)