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); //此行出错,啥原因?
}
}

解决方案 »

  1.   

    你知道Collection 跟 Collections 的区别么?List 怎么会是Collections的子类呢?
      

  2.   

    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
    }
      

  3.   

    谢谢,很多没有用java,忘了:(