CKTIS / Java
util.function.BiFunction: practical reference
util.function.BiFunction: practical reference: BiFunction<T,U,R> is a functional interface that maps two potentially different argument types to one result R.
Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Syntax
java.util.function.BiFunctionBiFunction<T,U,R> is a functional interface that maps two potentially different argument types to one result R.
Use apply for computations based on a pair of values, and andThen to transform the produced R into another type.
andThen does not transform the inputs: it invokes this function first and after second, relaying any exception from either.
A null after function throws NullPointerException when composing; a null result is passed to after, which may not accept it.
The example exercises the documented element in a small deterministic program and compares exact standard output.
Examples
public class Main {
public static void main(String[] args) throws Exception {
java.util.function.BiFunction<Integer, Integer, Integer> add = Integer::sum;
System.out.println(add.apply(20, 22));
}
}
Result
42
The example exercises the documented element in a small deterministic program and compares exact standard output.