接口 ThrowingFunction<T,R>

类型参数:
T - the type of the input to the function
R - the type of the result of the function
所有超级接口:
Function<T,R>
函数接口:
这是一个函数接口, 因此可用作 lambda 表达式或方法引用的赋值目标。

@FunctionalInterface public interface ThrowingFunction<T,R> extends Function<T,R>
A Function that allows invocation of code that throws a checked exception.
从以下版本开始:
4.0
作者:
Stephane Nicoll, Phillip Webb
  • 方法详细资料

    • applyWithException

      R applyWithException(T t) throws Exception
      Applies this function to the given argument, possibly throwing a checked exception.
      参数:
      t - the function argument
      返回:
      the function result
      抛出:
      Exception - on error
    • apply

      default R apply(T t)
      Default Function.apply(Object) that wraps any thrown checked exceptions (by default in a RuntimeException).
      指定者:
      apply 在接口中 Function<T,R>
      另请参阅:
    • apply

      default R apply(T t, BiFunction<String,Exception,RuntimeException> exceptionWrapper)
      Applies this function to the given argument, wrapping any thrown checked exceptions using the given exceptionWrapper.
      参数:
      exceptionWrapper - BiFunction that wraps the given message and checked exception into a runtime exception
      返回:
      a result
    • throwing

      default ThrowingFunction<T,R> throwing(BiFunction<String,Exception,RuntimeException> exceptionWrapper)
      Return a new ThrowingFunction where the apply(Object) method wraps any thrown checked exceptions using the given exceptionWrapper.
      参数:
      exceptionWrapper - BiFunction that wraps the given message and checked exception into a runtime exception
      返回:
      the replacement ThrowingFunction instance
    • of

      static <T, R> ThrowingFunction<T,R> of(ThrowingFunction<T,R> function)
      Lambda friendly convenience method that can be used to create a ThrowingFunction where the apply(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 Function.

      For example:

       stream.map(ThrowingFunction.of(Example::methodThatCanThrowCheckedException));
       
      类型参数:
      T - the type of the input to the function
      R - the type of the result of the function
      参数:
      function - the source function
      返回:
      a new ThrowingFunction instance
    • of

      static <T, R> ThrowingFunction<T,R> of(ThrowingFunction<T,R> function, BiFunction<String,Exception,RuntimeException> exceptionWrapper)
      Lambda friendly convenience method that can be used to create a ThrowingFunction where the apply(Object) method wraps any thrown checked exceptions using the given exceptionWrapper.

      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 Function.

      For example:

       stream.map(ThrowingFunction.of(Example::methodThatCanThrowCheckedException, IllegalStateException::new));
       
      类型参数:
      T - the type of the input to the function
      R - the type of the result of the function
      参数:
      function - the source function
      exceptionWrapper - the exception wrapper to use
      返回:
      a new ThrowingFunction instance