Package org.junit.jupiter.api.function
Interface ThrowingSupplier<T>
-
- Type Parameters:
T
- the type of argument supplied
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface @API(status=STABLE, since="5.0") public interface ThrowingSupplier<T>
ThrowingSupplier
is a functional interface that can be used to implement any generic block of code that returns an object and potentially throws aThrowable
.The
ThrowingSupplier
interface is similar toSupplier
, except that aThrowingSupplier
can throw any kind of exception, including checked exceptions.Rationale for throwing
Throwable
instead ofException
Although Java applications typically throw exceptions that are instances of
Exception
,RuntimeException
,Error
, orAssertionError
(in testing scenarios), there may be use cases where aThrowingSupplier
needs to explicitly throw aThrowable
. In order to support such specialized use cases,get()
is declared to throwThrowable
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description T
get()
Get a result, potentially throwing an exception.
-