代理类
Proxy.getProxyClass(ClassLoader loader,Class<?> … interfaces)获取一个代理类的字节码对象,返回Class类型
Proxy.newProxyInstance(ClassLoader loader,Class<?>[] interfaces,InvocationHandler h)获取一个动态代理类的实例对象
动态代理类:
class proxy{
InvocationHandler handler;
ProxyClass(InvocationHandler handler ){
this.handler = handler;
}
method_1(Object[] obj){
handler.invoke(proxy,Interfaces.getMethod(“method_1”),obj);
}
…..
method_n(Object[] obj)
handler.invoke(proxy,Interfaces.getMethod(“method_n”),obj);
}
InvocationHandler的对象只有一个invoke方法,这个方法相当于一个中继的方法,它的参数列表是obj—代理对象,method—代理对象调用的方法,args—调用方法的参数列表,是一个Object的数组.目标类的方法以及系统功能是在InvocationHandler的invoke方法里调用和实现的.
<!-- [if gte mso 9]><![endif]--><!-- [if gte mso 9]><![endif]--><!-- [if gte mso 10]>
代理类实现AOP框架