Interface CheckedBiConsumer<T,U>

Type Parameters:
T - first input type - 第一个输入类型
U - second input 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 CheckedBiConsumer<T,U>
CheckedBiConsumer - BiConsumer that can throw checked exceptions CheckedBiConsumer - 可抛出受检异常的双参消费者

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

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

Features | 主要功能:

  • Throw checked exceptions in lambda - 在 lambda 中抛出受检异常
  • Convert to standard BiConsumer (unchecked) - 转换为标准 BiConsumer
  • Silent execution - 静默执行
  • Chaining support (andThen) - 支持链式调用

Usage Examples | 使用示例:

CheckedBiConsumer<Path, String> writer =
    (path, content) -> Files.writeString(path, content);

BiConsumer<Path, String> wrapped = writer.unchecked();
writer.acceptQuietly(path, content);

// Chaining
writer.andThen((p, c) -> log.info("Written to " + p))
    .accept(path, content);

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
    void
    accept(T t, U u)
    Accept inputs, may throw checked exception 接受输入,可能抛出受检异常
    default void
    acceptQuietly(T t, U u)
    Accept silently, ignoring any checked or unchecked exception (but not Error) 静默接受,忽略任何受检或非受检异常(不包括 Error
    andThen(CheckedBiConsumer<? super T, ? super U> after)
    Chain with another consumer (execute this, then after) 与另一个消费者链接(先执行本函数,再执行 after)
    static <T,U> CheckedBiConsumer<T,U>
    of(BiConsumer<T,U> consumer)
    Wrap a standard BiConsumer as CheckedBiConsumer 将标准 BiConsumer 包装为 CheckedBiConsumer
    default BiConsumer<T,U>
    Convert to standard BiConsumer, wrapping checked exceptions 转换为标准 BiConsumer,包装受检异常
  • Method Details

    • accept

      void accept(T t, U u) throws Exception
      Accept inputs, may throw checked exception 接受输入,可能抛出受检异常
      Parameters:
      t - first input - 第一个输入
      u - second input - 第二个输入
      Throws:
      Exception - if operation fails - 如果操作失败
    • unchecked

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

      default void acceptQuietly(T t, U u)
      Accept silently, ignoring any checked or unchecked exception (but not Error) 静默接受,忽略任何受检或非受检异常(不包括 Error
      Parameters:
      t - first input - 第一个输入
      u - second input - 第二个输入
    • andThen

      default CheckedBiConsumer<T,U> andThen(CheckedBiConsumer<? super T, ? super U> after)
      Chain with another consumer (execute this, then after) 与另一个消费者链接(先执行本函数,再执行 after)
      Parameters:
      after - consumer to execute after this - 在本函数之后执行的消费者
      Returns:
      chained consumer - 链式消费者
    • of

      static <T,U> CheckedBiConsumer<T,U> of(BiConsumer<T,U> consumer)
      Wrap a standard BiConsumer as CheckedBiConsumer 将标准 BiConsumer 包装为 CheckedBiConsumer
      Type Parameters:
      T - first input type - 第一个输入类型
      U - second input type - 第二个输入类型
      Parameters:
      consumer - standard BiConsumer - 标准 BiConsumer
      Returns:
      CheckedBiConsumer wrapper - CheckedBiConsumer 包装器