本帖最后由 yuanshilieshou 于 2012-3-26 14:19 编辑
用Proxy.newInstance方法直接创建出代理对象
public class Proxy
{
public static void main(String[] args){
Collection proxy1 = (Collection)Proxy.newProxyInstance(
Collection.class.getClassLoader(),
new Class[] (Collection.class),
new InvocationHandler(){
public Object invoke(Object proxy,Method method,Object[] args)throws Throwable{
ArrayList target = new ArrayList();
Object retVal = method.invoke(target,args);
return retVal;
}
}
);
proxy1.add("ddsa");
proxy1.add("22a");
proxy1.add("3232");
System.out.println(proxy1.size());
}
}
即使操作的目标不是同一个,size怎么是0
|
|