Java 泛型问题 T extends Collections

我是松哥 2016-09-18 11:05:45
public class MyGeneric <T extends Collections> {
T x;
MyGeneric(T x) {
this.x = x;
}
public static void main(String[] str) {
List<String> arrayList = new ArrayList<String>();
MyGeneric<?> test = new MyGeneric<List<String>>(arrayList); //此行出错,啥原因?
}
}
...全文
162 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
我是松哥 2016-09-18
  • 打赏
  • 举报
回复
谢谢,很多没有用java,忘了:(
我是松哥 2016-09-18
  • 打赏
  • 举报
回复
Sorry, 知道原因了 Collections 应该是 Collection. public class MyGeneric <T extends Collection> { T x; MyGeneric(T x) { this.x = x; } public static void main(String[] str) { List<String> arrayList = new ArrayList<String>(); MyGeneric<?> test = new MyGeneric<List<String>>(arrayList); //ok } }
I,Frankenstein 2016-09-18
  • 打赏
  • 举报
回复
你知道Collection 跟 Collections 的区别么?List 怎么会是Collections的子类呢?

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧