返回信息流import java.util.*;
public class CollectionTest {
public static void main(String args[]) {
Collection books = new HashSet();
books.add("java");
}
出现错误提示
Multiple markers at this line
- Collection is a raw type. References to generic type Collection<E> should be
parameterized
- Type mismatch: cannot convert from HashSet to Collection
在Myeclipse上编译不通过,求大神指导
这是一条镜像帖。来源:北邮人论坛 / java / #37522同步于 2014/12/28
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
[问题]HashSet不能转成 Collection
xushu
2014/12/28镜像同步7 回复
订阅后,新回复会通过你的通知中心匿名送达。
7 条回复
【 在 xushu 的大作中提到: 】
: import java.util.*;
: public class CollectionTest {
: public static void main(String args[]) {
: ...................
Collection<String> books = new HashSet<String>();
books.add("java");
【 在 lixing 的大作中提到: 】
: [code=java]
: Collection<String> books = new HashSet<String>();
: books.add("java");
: ...................
跟泛型没关系吧?修改后还是不行
Multiple markers at this line
- Type mismatch: cannot convert from HashSet to Collection
- Collection is a raw type. References to generic type Collection<E> should be
parameterized
- The type HashSet is not generic; it cannot be parameterized with arguments <String>
【 在 xushu 的大作中提到: 】
: 跟泛型没关系吧?修改后还是不行
: Multiple markers at this line
: - Type mismatch: cannot convert from HashSet to Collection
: ...................
你用的什么版本的jdk?我这可以啊。1.7的。
【 在 lixing 的大作中提到: 】
: 你用的什么版本的jdk?我这可以啊。1.7的。
jdk1.8,刚才新下载了个eclipse上测试一下可以,但在Myeclipse上就不行,好奇怪。
【 在 xushu 的大作中提到: 】
: jdk1.8,刚才新下载了个eclipse上测试一下可以,但在Myeclipse上就不行,好奇怪。
MyEclipse好像用的是自带的jdk,需要切换成你安装的jdk版本
【 在 lixing 的大作中提到: 】
: MyEclipse好像用的是自带的jdk,需要切换成你安装的jdk版本
这个已经设置过,应该不是这个问题,。
Collection<? extends String>
【 在 xushu 的大作中提到: 】
: import java.util.*;
: public class CollectionTest {
: public static void main(String args[]) {
: ...................