读书人

父类引用指向子类对象Set s = new Has

发布时间: 2012-03-20 14:01:11 作者: rapoo

父类引用指向子类对象Set s = new HashSet();
为什么在eclipse里面写:
Set s = new HashSet();

Collection c = new ArrayList();
都会报错:
Multiple markers at this line
- Type mismatch: cannot convert from HashSet to Set
- HashSet is a raw type. References to generic type HashSet<E> should be
parameterized

可直接用java命令是可以编译通过的
是不是跟泛型有关啊?
请知道的兄弟帮忙讲解一下,谢谢!

[解决办法]

Java code
import java.util.*;public class Test {    public static void main(String[] args){        Set s = new HashSet();        s.add("1");        System.out.println(s);    }}
[解决办法]
楼主进入Eclipse 然后 点 window -> preferences -> java -> Errors/warnings 然后看右手边有个Generic Types 有个Usage of a raw type 将选项由error改为waring或者ignore。
该问题即可解决!

读书人网 >J2SE开发

热点推荐