java动态代理的特点
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基础
声明:本站所有文章,如无特殊说明或标注,均为爬虫抓取以及网友投稿,版权归原作者所有。