您的位置:首页 >java动态代理实例代码分析
发布于2023-04-30 阅读(100)
扫一扫,手机访问
说明
1、使用代理将对象包装起来,然后用该代理对象取代原始对象。
2、任何对原始对象的调用都要通过代理。代理对象决定是否以及何时将方法调用转到原始对象上。
实例
public static void main(String[] args) {
Roommate roommate = new Roommate("zhangsan");
Hungry proxyInstance = (Hungry) Proxy.newProxyInstance(
roommate.getClass().getClassLoader(),
roommate.getClass().getInterfaces(),
new RoommateInvocationHandler<Roommate>(roommate)
);
proxyInstance.callLunch();
}
//输出结果
下单前,我先帮你看下有没有平台优惠券吧
好饿,今天午饭点外卖吧
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
正版软件
正版软件
正版软件
正版软件
正版软件
1
2
3
7
9