黑马程序员技术交流社区
标题:
静态代理
[打印本页]
作者:
旺仔奶糖
时间:
2019-10-10 13:37
标题:
静态代理
public class ProxyTest {
public static void main(String[] args) {
//目标对象
final Target target = new Target();
//增强对象
final Advice advice = new Advice();
TargetInterface proxy = (TargetInterface) Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
advice.before();
Object obj = method.invoke(target, args);
advice.after();
return obj;
}
});
proxy.run();
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2