Interface IThrowingFunction<T,R>
- Type Parameters:
T- the type of the input to the functionR- the type of the result of the function
- All Superinterfaces:
Function<T,R>, ITypedThrowingFunction<T, R, Exception>
- All Known Subinterfaces:
ISerializableThrowingFunction<T,R>, IThrowingUnaryOperator<T>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface
public interface IThrowingFunction<T,R>
extends Function<T,R>, ITypedThrowingFunction<T, R, Exception>
A
Function that may throw a checked exception.
Represents a function that accepts one argument and produces a result.
This is a functional interface whose functional method is apply(Object).
- Since:
- 8.0.1
- Author:
- XIMA MEDIA GmbH
-
Method Summary
Modifier and TypeMethodDescriptiondefault Rstatic <T,R> IThrowingFunction <T, R> of(IThrowingFunction<T, R> fn) Returns the given supplier, for improved variable inference.static <T,R> IThrowingFunction <T, R> throwingFunction(IThrowingFunction<T, R> fn) Returns the given function, for improved variable inference.Gets a result.
-
Method Details
-
tryApply
-
apply
-
of
Returns the given supplier, for improved variable inference. Sometimes you need to create local variables and assign them to a new lambda. This does not work well with variable inference, as Java cannot infer the type of anonymous lambdas. This utility method lets you write slightly more readable code like this:final var fn = ISerializableThrowingFunction.of(t -> ...);
You can also use this helper method to create a function from a lambda expression that throws checked exceptions and use the result as aFunctionthat rethrows checked exceptions as unchecked ones.- Type Parameters:
T- the type of the argument expected by the functionR- the type of the result of the function- Parameters:
fn- Function to return.- Returns:
- The given supplier.
-
throwingFunction
Returns the given function, for improved variable inference. Sometimes you need to create local variables and assign them to a new lambda. This does not work well with variable inference, as Java cannot infer the type of anonymous lambdas. This utility method lets you write slightly more readable code like this:final var fn = throwingFunction(t -> ...);
You can also use this helper method to create a function from a lambda expression that throws checked exceptions and use the result as aFunctionthat rethrows checked exceptions as unchecked ones.- Type Parameters:
T- the type of the argument expected by the functionR- the type of the result of the function- Parameters:
fn- Function to return.- Returns:
- The given supplier.
-