资源介绍
java动态代理
public class HireProxy implements InvocationHandler {
//被代理的真实角色
private Object obj;
public HireProxy(Object obj) {
super();
this.obj = obj;
}
//第二个参数method,被代理对象的接口方法
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("做前置工作");
System.out.println("--------------------------");
if(args != null){
for(Object o : args){
System.out.println(o);
}
}
System.out.println("--------------------------");
Object invoke = method.invoke(obj, args);
System.out.println("做后置工作");
return invoke;
}
}