62,614
社区成员
发帖
与我相关
我的任务
分享
private static class TestBeanHander implements InvocationHandler {
private Object obj;
public TestBeanHander(Object obj) {
this.obj = obj;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
System.out.println(proxy.getClass().getName());
System.out.println("JDK-START");
Object re = method.invoke(obj, args);
System.out.println("JDK-END");
return re;
}
}
ITestBean tb = new TestBean();
tb = (ITestBean) Proxy.newProxyInstance(tb.getClass().getClassLoader(),
tb.getClass().getInterfaces(), new TestBeanHander(tb));
有关JDK动态代理的原理,可以看看我的博客
《JDK动态代理为什么必须用接口以及与CGLIB的对比》
http://blog.csdn.net/MagicianLiu/archive/2009/04/24/4107497.aspx
tb.add();