Interface CheckedCallable<V>

Type Parameters:
V - 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 CheckedCallable<V>
Checked Callable - Enhanced Callable with convenience methods 可抛出受检异常的 Callable - 增强 JDK Callable 提供便捷方法

Extends JDK Callable with additional convenience methods.

扩展 JDK Callable,提供额外的便捷方法。

Features | 主要功能:

  • Convert to JDK Callable (toCallable) - 转换为 JDK Callable
  • Silent execution (callQuietly/callOrDefault) - 静默执行
  • Interop with CheckedSupplier - 与 CheckedSupplier 互操作

Usage Examples | 使用示例:

CheckedCallable<String> task = () -> Files.readString(path);
Future<String> future = executor.submit(task.toCallable());
String result = task.callOrDefault("fallback");

Security | 安全性:

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

    Modifier and Type
    Method
    Description
    Executes and returns a result, may throw a checked exception 执行并返回结果,可能抛出受检异常
    default V
    callOrDefault(V defaultValue)
    Silently calls, returning the default value on exception 静默调用,异常时返回默认值
    default V
    Silently calls, returning null on exception 静默调用,异常时返回 null
    static <V> CheckedCallable<V>
    from(CheckedSupplier<V> supplier)
    Converts a CheckedSupplier to a CheckedCallable 将 CheckedSupplier 转换为 CheckedCallable
    static <V> CheckedCallable<V>
    of(Callable<V> callable)
    Wraps a JDK Callable as a CheckedCallable 将 JDK Callable 包装为 CheckedCallable
    default Callable<V>
    Converts 转换为 JDK Callable
  • Method Details

    • call

      V call() throws Exception
      Executes and returns a result, may throw a checked exception 执行并返回结果,可能抛出受检异常
      Returns:
      the result | 结果
      Throws:
      Exception - if the condition is not met | 如果操作失败
    • toCallable

      default Callable<V> toCallable()
      Converts 转换为 JDK Callable
      Returns:
      Callable
    • callQuietly

      default V callQuietly()
      Silently calls, returning null on exception 静默调用,异常时返回 null
      Returns:
      the result | 结果或 null
    • callOrDefault

      default V callOrDefault(V defaultValue)
      Silently calls, returning the default value on exception 静默调用,异常时返回默认值
      Parameters:
      defaultValue - the default value | 默认值
      Returns:
      the result | 结果或默认值
    • of

      static <V> CheckedCallable<V> of(Callable<V> callable)
      Wraps a JDK Callable as a CheckedCallable 将 JDK Callable 包装为 CheckedCallable
      Type Parameters:
      V - the value | 返回值类型
      Parameters:
      callable - JDK Callable
      Returns:
      CheckedCallable
    • from

      static <V> CheckedCallable<V> from(CheckedSupplier<V> supplier)
      Converts a CheckedSupplier to a CheckedCallable 将 CheckedSupplier 转换为 CheckedCallable
      Type Parameters:
      V - the value | 返回值类型
      Parameters:
      supplier - CheckedSupplier
      Returns:
      CheckedCallable