本帖最后由 张源锋 于 2013-4-6 22:51 编辑
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
public class InvoceHandler implements InvocationHandler{
Object target ;
public InvoceHandler(Object target){
this.target=target;
}
public void begin(){
System.out.println("save start");
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
this.begin();
method.invoke(target, args);
return null;
}
}
import java.lang.reflect.Proxy;
public class Test {
public static void main(String[] args) {
InvoceHandler in =new InvoceHandler(new UserDao());
UserDaoInterface u =(UserDaoInterface)Proxy.newProxyInstance(UserDao.class.getClassLoader(),
UserDao.class.getInterfaces(),in);
u.save();
}
}
谁能告诉我产生这个 代理的过程,我现在一个头两个大。希望大神们能用通俗点语言解释一下,小弟谢过了
|