标签:
//PECS:producer-extends-comsumer-superimport com.google.common.collect.Lists; import java.util.Arrays; import java.util.List; /** * Created by jianjun.yu on 15-4-21. */ public class GTest { public static void main(String[] args) { List<Integer> ints = Arrays.asList(1, 2, 3); filterObject(ints); List<Number> objs = Arrays.<Number>asList(1f, 1, 2l); filterObject(objs); List<Integer> il = Lists.newArrayList(); getObject(il); List<Number> nl = Lists.newArrayList(); getObject(nl); } public static <T>void filterObject(Iterable<? extends Number> list) { for (Number t : list) { if (t != null) { System.out.println(t); } } } public static <T>void getObject(List<? super Integer> list) { for (int i = 0; i < 10; i++) { list.add(i); } } //PECS:producer-extends-comsumer-super }
标签:
原文地址:http://blog.csdn.net/minna_d/article/details/45341593