代码:
Collection c = new LinkedList();
c.add(new Integer(10));请问这样有问题吗,eclipse有如下提示,是什么意思,怎么解决?
Type safety: The method add(Object) belongs to the raw type Collection. References to generic type
Collection<E> should be parameterized
Collection c = new LinkedList();
c.add(new Integer(10));请问这样有问题吗,eclipse有如下提示,是什么意思,怎么解决?
Type safety: The method add(Object) belongs to the raw type Collection. References to generic type
Collection<E> should be parameterized
解决方案 »
- 请问throw new exception在哪儿捕获的?
- 关于java数组之间的直接赋值
- 请教个问题??为什么(有时候)不能生成类文件。
- 可不可以从标签取出的list,赋值给java代码,然后再让其顺序打乱取前几个元素重新放到新List里面?
- 实在搞不懂这个输出结果,帮帮忙,谢谢!
- 求去除文章左右的 的方法
- java是否有word接口?(新手请教)
- 有 org.apache.xerces.parsers.DOMParser吗?
- 鼠标dragged时,怎么做出虚框效果,用于选中物件?
- 请问如何用java知道当前运行程序得到焦点的对象?请赐教。谢谢!!!
- eclipse如何打开已有的工程(eclipse的)
- 100分,帮我解释一下。
我没使用过Collection 类但是它肯定是 LinkedList的扩展类,所以应该也是List的扩展类,
那么它的ADD 方法,的参数应该是一个控件 而不是多个:
只能是int 不能是有int 组成的一个数组。
这是我想的。
Collection<Integer>c = new LinkedList<Integer>(); // 或者你可以 new LinkedList<Number>();c.add(new Integer(10));Type safety: The method add(Object) belongs to the raw type Collection. References to generic type
Collection<E> should be parameterized就是说你如果用参数表示的类在使用时如果给出了具体的参数的话,以后在 Cast 时就可以省略了,因为编译器能检查你当时定义变量时使用了类型参数, 以后只能往里面添加正确的类型的变量,如果变量类型不是定义的就会出错,比如上面定义集合用了 <Number> 那么以后只能往里面添加 Number 的或子类的实例,否则无法编译.
解释得很明白,懂了不过我觉得这个warning没必要存在,能否对eclipse进行设置一下呢?