java8函数式编程-BiFunction<T,U,R>

BiFunction<T,U,R> 接收 2个参数 一个结果

@FunctionalInterface
public interface BiFunction<T, U, R> {

    /**
     * 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<Float,Float,Float> 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));
    }
image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容