Package de.xima.fc.interfaces
Interface IThrowingSupplier<T>
-
- Type Parameters:
T
- the type of results supplied by this supplier
- All Superinterfaces:
Supplier<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 IThrowingSupplier<T> extends Supplier<T>
ASupplier
that may throw a checked exception.Represents a supplier of results.
There is no requirement that a new or distinct result be returned each time the supplier is invoked.
This is a
functional interface
whose functional method istryGet()
.- Since:
- 8.0.0
- Author:
- XIMA MEDIA GmbH
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default T
get()
static <T> IThrowingSupplier<T>
of(IThrowingSupplier<T> supplier)
Returns the given supplier, for improved variable inference.T
tryGet()
Gets a result.
-
-
-
Method Detail
-
tryGet
T tryGet() throws Exception
Gets a result.- Returns:
- The result
- Throws:
Exception
- When this operation fails.
-
of
static <T> IThrowingSupplier<T> of(IThrowingSupplier<T> supplier)
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 an anonymous lambda. This utility method lets you write slightly more readable code like this:final var supplier = IThrowingSupplier.of(t -> ...);
- Type Parameters:
T
- the type of results supplied by this supplier- Parameters:
supplier
- Supplier to return.- Returns:
- The given supplier.
-
-