BiFunction<T,U,R> 接收 2個參數(shù) 一個結(jié)果
@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);
}
實現(xiàn)兩個數(shù)的 加減乘除
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