接口 ThrowingConsumer<T>
- 类型参数:
T- the type of the input to the operation
- 所有超级接口:
Consumer<T>
- 所有已知子接口:
ContextResource,InputStreamSource,Resource,WritableResource
- 所有已知实现类:
AbstractFileResolvingResource,AbstractResource,AppendableConsumerInputStreamSource,ByteArrayResource,ClassPathResource,ClassRelativeResourceLoader.ClassRelativeContextResource,DefaultResourceLoader.ClassPathContextResource,DescriptiveResource,EncodedResource,FileSystemResource,FileSystemResourceLoader.FileSystemContextResource,FileUrlResource,InputStreamResource,ModuleResource,PathResource,ResourceDecorator,UrlResource,WritableResourceDecorator
- 函数接口:
- 这是一个函数接口, 因此可用作 lambda 表达式或方法引用的赋值目标。
A
Consumer that allows invocation of code that throws a checked
exception.- 从以下版本开始:
- 4.0
- 作者:
- Stephane Nicoll, Phillip Webb
-
方法概要
修饰符和类型方法说明default voidDefaultConsumer.accept(Object)that wraps any thrown checked exceptions (by default in aRuntimeException).default voidaccept(T t, BiFunction<String, Exception, RuntimeException> exceptionWrapper) Performs this operation on the given argument, wrapping any thrown checked exceptions using the givenexceptionWrapper.voidPerforms this operation on the given argument, possibly throwing a checked exception.static <T> ThrowingConsumer<T>of(ThrowingConsumer<T> consumer) Lambda friendly convenience method that can be used to create aThrowingConsumerwhere theaccept(Object)method wraps any checked exception thrown by the supplied lambda expression or method reference.static <T> ThrowingConsumer<T>of(ThrowingConsumer<T> consumer, BiFunction<String, Exception, RuntimeException> exceptionWrapper) Lambda friendly convenience method that can be used to create aThrowingConsumerwhere theaccept(Object)method wraps any thrown checked exceptions using the givenexceptionWrapper.default ThrowingConsumer<T>throwing(BiFunction<String, Exception, RuntimeException> exceptionWrapper) Return a newThrowingConsumerwhere theaccept(Object)method wraps any thrown checked exceptions using the givenexceptionWrapper.
-
方法详细资料
-
acceptWithException
Performs this operation on the given argument, possibly throwing a checked exception.- 参数:
t- the input argument- 抛出:
Exception- on error
-
accept
DefaultConsumer.accept(Object)that wraps any thrown checked exceptions (by default in aRuntimeException). -
accept
Performs this operation on the given argument, wrapping any thrown checked exceptions using the givenexceptionWrapper.- 参数:
exceptionWrapper-BiFunctionthat wraps the given message and checked exception into a runtime exception
-
throwing
default ThrowingConsumer<T> throwing(BiFunction<String, Exception, RuntimeException> exceptionWrapper) Return a newThrowingConsumerwhere theaccept(Object)method wraps any thrown checked exceptions using the givenexceptionWrapper.- 参数:
exceptionWrapper-BiFunctionthat wraps the given message and checked exception into a runtime exception- 返回:
- the replacement
ThrowingConsumerinstance
-
of
Lambda friendly convenience method that can be used to create aThrowingConsumerwhere theaccept(Object)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
Consumer.For example:
list.forEach(ThrowingConsumer.of(Example::methodThatCanThrowCheckedException));
- 类型参数:
T- the type of the input to the operation- 参数:
consumer- the source consumer- 返回:
- a new
ThrowingConsumerinstance
-
of
static <T> ThrowingConsumer<T> of(ThrowingConsumer<T> consumer, BiFunction<String, Exception, RuntimeException> exceptionWrapper) Lambda friendly convenience method that can be used to create aThrowingConsumerwhere theaccept(Object)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
Consumer.For example:
list.forEach(ThrowingConsumer.of(Example::methodThatCanThrowCheckedException, IllegalStateException::new));
- 类型参数:
T- the type of the input to the operation- 参数:
consumer- the source consumerexceptionWrapper- the exception wrapper to use- 返回:
- a new
ThrowingConsumerinstance
-