父类引用指向子类对象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命令是可以编译通过的
是不是跟泛型有关啊?
请知道的兄弟帮忙讲解一下,谢谢!
[解决办法]
import java.util.*;
public class Test {
public static void main(String[] args){
Set s = new HashSet();
s.add("1");
System.out.println(s);
}
}