Class clazzProxy1 = Proxy.getProxyClass(Collection.class.getClassLoader(), Collection.class);
//这个Class clazzProxy1 是代理类么?
Constructor constructor = clazzProxy1.getConstructor(InvocationHandler.class);
//这个constructor 是代理类的InvocationHandler参数的构造方法
class MyInvocationHander1 implements InvocationHandler //定义个MyInvocationHander1类 实现接口 InvocationHandler
{
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
// TODO Auto-generated method stub
return null;
}
}
Collection proxy1 = (Collection)constructor.newInstance(new MyInvocationHander1());
//这句话是什么意思。为什么要建立个 Collection。
Collection proxy2 = (Collection)constructor.newInstance(
new InvocationHandler(){
public Object invoke(Object proxy, Method method, Object[] args)throws Throwable
{
return null;
}
});
//为何要定义一个Collection集合
final ArrayList target = new ArrayList();
Collection proxy3 = (Collection)getProxy(target,new MyAdvice());
如何写一个代理类呢,
怎样才算创建了该代理类的实例对象 |