首页 > 编程语言 > 详细

java迭代器PECS

时间:2015-04-28 22:56:40      阅读:312      评论:0      收藏:0      [点我收藏+]


//PECS:producer-extends-comsumer-super

import 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
}





java迭代器PECS

原文:http://blog.csdn.net/minna_d/article/details/45341593

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!