T
- The type of the first input to the operation.U
- The type of the second input to the operation.R
- The type of the result of the function.E
- The type of the exception that can be thrown.@FunctionalInterface public interface ThrowingBiFunction<T,U,R,E extends Exception> extends BiFunction<T,U,R>
The ThrowingFunction
distinguishes itself from BiFunction
by
allowing the functional interface to throw an Exception
. This can be
used to allow lambda expressions to propagate checked exceptions up the
expression's call stack. An example of this pattern:
BiFunction<Integer,Integer,String> function = Throwing.<Integer,Integer,String>rethrow((i, j) -> {
if (i == 0)
throw new IllegalArgumentException("i=" + i);
return String.valueOf(i);
});
for (int i = 3; i >= 0; --i)
function.accept(i, -i);
Throwing
Modifier and Type | Method and Description |
---|---|
default R |
apply(T t,
U u) |
R |
applyThrows(T t,
U u)
Performs this operation on the given argument, allowing an exception to be
thrown.
|
andThen
Copyright © 2020 LibJ. All rights reserved.