5.1 代理模式(Proxy)
1.proxy 提供了用于创建代理类和实例的静态方法;
2.proxy 是所有动态代理类的父类
创建代理类的static的方法
1.返回代理的java.lang.Class的代理对象
I.需要接收类加载器
II.需要被代理的接口数组作为参数
public static Class<?> getProxyClass(ClassLoader loader, Class<?>… interfaces)throws IllegalArgumentException
2.返回代理对象
I.需要指定类加载器
II.需要被代理的接口数组作为参数
III.需要InvocationHandler对象public static
Object newProxyInstance(ClassLoader loader,
Class<?>[] interfaces,
InvocationHandler h) throws IllegalArgumentException
就相当于
Proxy.getProxyClass(ClassLoader.getSystemClassLoader(),Interface.class.getInterfaces())
.getConstructor(new Class[]{Interface.class}).newInstance(…);