Interface CheckedBiFunction<T,U,R>

Type Parameters:
T - first input type - 第一个输入类型
U - second input type - 第二个输入类型
R - return type - 返回值类型
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface CheckedBiFunction<T,U,R>
CheckedBiFunction - BiFunction that can throw checked exceptions CheckedBiFunction - 可抛出受检异常的双参函数

Extends the concept of JDK BiFunction to allow throwing checked exceptions.

扩展 JDK BiFunction 的概念,支持抛出受检异常。

Features | 主要功能:

  • Throw checked exceptions in lambda - 在 lambda 中抛出受检异常
  • Convert to standard BiFunction (unchecked) - 转换为标准 BiFunction
  • Silent execution with defaults - 静默执行并返回默认值
  • Composition support - 支持函数组合

Usage Examples | 使用示例:

CheckedBiFunction<Path, Charset, String> readFile =
    (path, charset) -> Files.readString(path, charset);

BiFunction<Path, Charset, String> wrapped = readFile.unchecked();
String content = readFile.applyOrDefault(path, charset, "fallback");

Security | 安全性:

  • Thread-safe: Yes (stateless) - 线程安全: 是 (无状态)
  • Null-safe: No - 空值安全: 否
Since:
JDK 25, opencode-base-functional V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default <V> CheckedBiFunction<T,U,V>
    andThen(CheckedFunction<? super R, ? extends V> after)
    Compose with another function (execute this, then after) 与另一个函数组合(先执行本函数,再执行 after)
    apply(T t, U u)
    Apply function to arguments, may throw checked exception 应用函数到参数,可能抛出受检异常
    default R
    applyOrDefault(T t, U u, R defaultValue)
    Apply silently, returning default value on exception 静默应用,异常时返回默认值
    default R
    applyQuietly(T t, U u)
    Apply silently, returning null on exception 静默应用,异常时返回 null
    static <T,U,R> CheckedBiFunction<T,U,R>
    of(BiFunction<T,U,R> function)
    Wrap a standard BiFunction as CheckedBiFunction 将标准 BiFunction 包装为 CheckedBiFunction
    default BiFunction<T,U,R>
    Convert to standard BiFunction, wrapping checked exceptions 转换为标准 BiFunction,包装受检异常
  • Method Details

    • apply

      R apply(T t, U u) throws Exception
      Apply function to arguments, may throw checked exception 应用函数到参数,可能抛出受检异常
      Parameters:
      t - first input - 第一个输入
      u - second input - 第二个输入
      Returns:
      result - 结果
      Throws:
      Exception - if operation fails - 如果操作失败
    • unchecked

      default BiFunction<T,U,R> unchecked()
      Convert to standard BiFunction, wrapping checked exceptions 转换为标准 BiFunction,包装受检异常
      Returns:
      BiFunction that wraps checked exceptions - 包装受检异常的 BiFunction
    • applyQuietly

      default R applyQuietly(T t, U u)
      Apply silently, returning null on exception 静默应用,异常时返回 null
      Parameters:
      t - first input - 第一个输入
      u - second input - 第二个输入
      Returns:
      result or null - 结果或 null
    • applyOrDefault

      default R applyOrDefault(T t, U u, R defaultValue)
      Apply silently, returning default value on exception 静默应用,异常时返回默认值
      Parameters:
      t - first input - 第一个输入
      u - second input - 第二个输入
      defaultValue - default value on error - 错误时的默认值
      Returns:
      result or default value - 结果或默认值
    • andThen

      default <V> CheckedBiFunction<T,U,V> andThen(CheckedFunction<? super R, ? extends V> after)
      Compose with another function (execute this, then after) 与另一个函数组合(先执行本函数,再执行 after)
      Type Parameters:
      V - result type of after function - after 函数的结果类型
      Parameters:
      after - function to apply after this - 在本函数之后应用的函数
      Returns:
      composed function - 组合后的函数
    • of

      static <T,U,R> CheckedBiFunction<T,U,R> of(BiFunction<T,U,R> function)
      Wrap a standard BiFunction as CheckedBiFunction 将标准 BiFunction 包装为 CheckedBiFunction
      Type Parameters:
      T - first input type - 第一个输入类型
      U - second input type - 第二个输入类型
      R - return type - 返回值类型
      Parameters:
      function - standard BiFunction - 标准 BiFunction
      Returns:
      CheckedBiFunction wrapper - CheckedBiFunction 包装器