泛型类与静态泛型方法 Cannot make a static reference to the non-static type
public static <E> ToList<E> create(E...ts),这样就不会报错了。这个E类型为这个类ToList没有任何关系,可以直接ToList.create(....)这样调用,
例如:
ToList.create("1","2");返回的就是ToList<String>
ToList.create(1,2);返回的就是ToList<Integer>。
而下面一种情况就不同:
crreate是ToList<E>的一个成员方法,只有当你new出来一个这样的类时,create方法才可以使用。所以,create方法里的E的类型,取决于你new这个类时的传递的是什么类型 ,
例如:
ToList<String> list1 = new ToList<String>(); list1.create("1","2")返回的就是ToList<String>类型;
ToList<Integer> list1 = new ToList<Integer>(); list1.create(1,2)返回的就是ToList<Integer>类型。