码迷,mamicode.com
首页 > 编程语言 > 详细

java迭代器PECS

时间:2015-04-28 22:56:47      阅读:307      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!