List list=mull;
list.add(对象);
list.add(对象);为什么会报list是空指针,这个应该怎么去写我这么写
List list=new List();
会报错误
Cannot instantiate the type List
请详细说说知识点
list.add(对象);
list.add(对象);为什么会报list是空指针,这个应该怎么去写我这么写
List list=new List();
会报错误
Cannot instantiate the type List
请详细说说知识点
LIST是接口啊.楼主
LIST a = new ArrayList()或者LinkedList之类的就行了啊
list.add(对象);
List list=mull;
list.add(对象);
list.add(对象); 为什么会报list是空指针,这个应该怎么去写 大哥,你的list就是个null,当然会报空指针异常了。
List list=new List();
会报错误
Cannot instantiate the type List 接口和抽象类都不能实例化。只有具体类才能实例化。建议楼主先找本Java基本语法的书来看看。这种问题不建议在论坛上问
这个是对的。List是接口不能实例化
list.add(对象);
list.add(对象); 就行了。
list.add(对象);
list.add(对象); 为什么会报list是空指针,这个应该怎么去写
你的list直接赋值为null,后面直接调用,当然报空指针我这么写
List list=new List();
会报错误
Cannot instantiate the type List
请详细说说知识点List是接口,不是实现类,当然不能直接实例化,你必须找List的具体类,比如ArrayList或者LinkedList之类的
Map map = new HashMap();, 接口向上转型方便,有利于多态,所以大家不喜欢用HashMap map = new HashMap(),这种方式