Java新特性玩转JDK8之函数式编程 BiFunction

DBC 1.7K 0
BiFunction Function只能接收⼀个参数,如果要传递两个参数,则⽤ BiFunction
小例子
public class Main {
    public static void main(String[] args) {
        System.out.println(operator(10, 21, (a, b) -> a + b));
        System.out.println(operator(10, 2, (a, b) -> a - b));
        System.out.println(operator(8, 4, (a, b) -> a * b));
        System.out.println(operator(10, 2, (a, b) -> a / b));
    }

    public static Integer operator(Integer a, Integer b, BiFunction<Integer,
            Integer, Integer> bf) {
        return bf.apply(a, b);
    }

}

发表评论 取消回复
表情 图片 链接 代码

分享