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
网友评论