接口 ThrowingSupplier<T>
- 类型参数:
T- the type of results supplied by this supplier
- 所有超级接口:
Supplier<T>
A
Supplier that allows invocation of code that throws a checked
exception.- 从以下版本开始:
- 4.0
- 作者:
- Stephane Nicoll, Phillip Webb
-
方法概要
修饰符和类型方法说明default Tget()DefaultSupplier.get()that wraps any thrown checked exceptions (by default in aRuntimeException).default Tget(BiFunction<String, Exception, RuntimeException> exceptionWrapper) Gets a result, wrapping any thrown checked exceptions using the givenexceptionWrapper.Gets a result, possibly throwing a checked exception.static <T> ThrowingSupplier<T>of(ThrowingSupplier<T> supplier) Lambda friendly convenience method that can be used to create aThrowingSupplierwhere theget()method wraps any checked exception thrown by the supplied lambda expression or method reference.static <T> ThrowingSupplier<T>of(ThrowingSupplier<T> supplier, BiFunction<String, Exception, RuntimeException> exceptionWrapper) Lambda friendly convenience method that can be used to createThrowingSupplierwhere theget()method wraps any thrown checked exceptions using the givenexceptionWrapper.default ThrowingSupplier<T>throwing(BiFunction<String, Exception, RuntimeException> exceptionWrapper) Return a newThrowingSupplierwhere theget()method wraps any thrown checked exceptions using the givenexceptionWrapper.
-
方法详细资料
-
getWithException
Gets a result, possibly throwing a checked exception.- 返回:
- a result
- 抛出:
Exception- on error
-
get
DefaultSupplier.get()that wraps any thrown checked exceptions (by default in aRuntimeException). -
get
Gets a result, wrapping any thrown checked exceptions using the givenexceptionWrapper.- 参数:
exceptionWrapper-BiFunctionthat wraps the given message and checked exception into a runtime exception- 返回:
- a result
-
throwing
default ThrowingSupplier<T> throwing(BiFunction<String, Exception, RuntimeException> exceptionWrapper) Return a newThrowingSupplierwhere theget()method wraps any thrown checked exceptions using the givenexceptionWrapper.- 参数:
exceptionWrapper-BiFunctionthat wraps the given message and checked exception into a runtime exception- 返回:
- the replacement
ThrowingSupplierinstance
-
of
Lambda friendly convenience method that can be used to create aThrowingSupplierwhere theget()method wraps any checked exception thrown by the supplied lambda expression or method reference.This method can be especially useful when working with method references. It allows you to easily convert a method that throws a checked exception into an instance compatible with a regular
Supplier.For example:
optional.orElseGet(ThrowingSupplier.of(Example::methodThatCanThrowCheckedException));
- 类型参数:
T- the type of results supplied by this supplier- 参数:
supplier- the source supplier- 返回:
- a new
ThrowingSupplierinstance
-
of
static <T> ThrowingSupplier<T> of(ThrowingSupplier<T> supplier, BiFunction<String, Exception, RuntimeException> exceptionWrapper) Lambda friendly convenience method that can be used to createThrowingSupplierwhere theget()method wraps any thrown checked exceptions using the givenexceptionWrapper.This method can be especially useful when working with method references. It allows you to easily convert a method that throws a checked exception into an instance compatible with a regular
Supplier.For example:
optional.orElseGet(ThrowingSupplier.of(Example::methodThatCanThrowCheckedException, IllegalStateException::new));
- 类型参数:
T- the type of results supplied by this supplier- 参数:
supplier- the source supplierexceptionWrapper- the exception wrapper to use- 返回:
- a new
ThrowingSupplierinstance
-