package PlayProxy;
public class Car implements IVehical{
public void run() {
System.out.println("Car会跑");
}
public void boom() {
System.out.println("Boom!");
}
}
InvocationHandler实现类
package PlayProxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
public class VehicalInvacationHandler implements InvocationHandler {
private final Object target;
public VehicalInvacationHandler(Object o){
this.target = o;
}
/*
invoke三个参数:
proxy:就是代理对象,newProxyInstanc
最基础的动态代理Demo主函数public class App { public static void main(String[] args) { System.setProperty("sun.misc.ProxyGenerator.saveGeneratedFiles","true"); Integer a = 0; IVehical car = new Car(); InvocationHandler handler