public static void main(String[] args) {
//创建动态类,并实例其对象
Collection proxy2=(Collection) Proxy.newProxyInstance(Collection.class.getClassLoader(),
new Class[]{Collection.class},
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
return null;
}
});
proxy2.add("zxx");
proxy2.add("lhm");
proxy2.add("bxd");
System.out.println(proxy2.size());
}
运行结果:
Exception in thread "main" java.lang.NullPointerException at com.sun.proxy.$Proxy0.add(Unknown Source) at cn.itcast.day03.ProxyTest.main(ProxyTest.java:31)请问是哪里出了错误?
|