public class GeneriDemo { public static void main(String[] args) { ArrayList<String> list1 = new ArrayList<>(); ArrayList<Integer> list2 = new ArrayList<>(); show(list1); show(list2); ArrayList<Number> list3 = new ArrayList<>(); ArrayList<Object> list4 = new ArrayList<>(); showSuper(list3); showSuper(list4); showExtends(list3); showExtends(list2); } private static void show(ArrayList<?> list) { System.out.println(list); } // 表示传递进来的集合类型,可以是Number及它的所有父类 private static void showSuper(ArrayList<? super Number> list) { System.out.println(list); } // 表示传递进来的集合类型,可以是Number及它的所有子类 private static void showExtends(ArrayList<? extends Number> list) { System.out.println(list); } }
标签:show,通配符,ArrayList,list,static,泛型,new,void From: https://www.cnblogs.com/weiduaini/p/17197876.html