java8函数式编程-BiFunction

BiFunction 接收 2个参数 一个结果

@FunctionalInterface
public interface BiFunction {

    /**
     * Applies this function to the given arguments.
     *
     * @param t the first function argument
     * @param u the second function argument
     * @return the function result
     */
    R apply(T t, U u);
}

实现两个数的 加减乘除

    private static float bifloat(float a,float b,BiFunction biFunction){
        return biFunction.apply(a, b);
    }


    public static void main(String[] args) {
        System.out.println(bifloat(2, 3,(a,b)->a+b));
        System.out.println(bifloat(2, 3,(a,b)->a-b));
        System.out.println(bifloat(2, 3,(a,b)->a*b));
        System.out.println(bifloat(2, 3,(a,b)->a/b));
    }
java8函数式编程-BiFunction<T,U,R>_第1张图片
image.png

你可能感兴趣的:(java8函数式编程-BiFunction)