解决使用 lambda 表达式不能使用 获取 index 的问题

2018-06-04  本文已影响0人  程序猿_小刚
/**
 * Iterable 的工具类
 * @author mazg
 *
 */
public class Iterables {
    
    public static <E> void forEach(Iterable<? extends E> elements,BiConsumer<Integer,? super E> action){
        Objects.requireNonNull(elements);
        Objects.requireNonNull(action);
        int index = 0;
        for (E element : elements) {
            action.accept(index++, element);
        }
    }
}
上一篇 下一篇

猜你喜欢

热点阅读