Interface ThrowingSupplier<T>
-
- Type Parameters:
T- the type of argument supplied
- All Superinterfaces:
Executable
- 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> extends ExecutableThrowingSupplieris a functional interface that can be used to implement any generic block of code that returns an object and potentially throws aThrowable.The
ThrowingSupplierinterface is similar toSupplier, except that aThrowingSuppliercan throw any kind of exception, including checked exceptions.As of JUnit Jupiter 5.3,
ThrowingSupplierextendsExecutable, providing a default implementation ofexecute()that delegates toget()and ignores the return value. This allows the Java compiler to disambiguate betweenThrowingSupplierandExecutablewhen performing type inference for a lambda expression or method reference supplied to an overloaded method that accepts either aThrowingSupplieror anExecutable.Rationale for throwing
Throwableinstead ofExceptionAlthough Java applications typically throw exceptions that are instances of
Exception,RuntimeException,Error, orAssertionError(in testing scenarios), there may be use cases where aThrowingSupplierneeds 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 Default Methods Modifier and Type Method Description default voidexecute()Delegates toget()and ignores the return value.Tget()Get a result, potentially throwing an exception.
-
-
-
Method Detail
-
execute
@API(status=STABLE, since="5.3") default void execute() throws java.lang.ThrowableDelegates toget()and ignores the return value.This default method is not intended to be overridden. See class-level documentation for further details.
- Specified by:
executein interfaceExecutable- Throws:
java.lang.Throwable- Since:
- 5.3
- See Also:
get()
-
get
T get() throws java.lang.Throwable
Get a result, potentially throwing an exception.- Returns:
- a result
- Throws:
java.lang.Throwable
-
-