Collection proxy=(Collection)Proxy.newProxyInstance(
Collection.class.getClassLoader(),
new Class[]{Collection.class},
new InvocationHandler(){
@Override
public Object invoke(Object arg0, Method method, Object[] arg2)
throws Throwable {
ArrayList target=new ArrayList();
return method.invoke(target,args);
}
});
proxy.add("xxx");
proxy.add("lhm");
proxy.add("bxd");
System.out.println(proxy.size());
错误如下:Exception in thread "main" java.lang.IllegalArgumentException: wrong number of arguments
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at FileTest$1.invoke(FileTest.java:22)
at com.sun.proxy.$Proxy0.size(Unknown Source)
at FileTest.main(FileTest.java:29)
|
|