Callable vs Supplier interface in java

前端 未结 3 1394
春和景丽
春和景丽 2021-02-19 16:35

The Callable and Supplier functional interfaces in java.util.concurrent and java.util.function packages respectively have the

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-19 17:32

    For Runnable and Callable, they've been parts of the concurrent package since Java 6. It implies that both of them are ready to be submitted to an Executor and run asynchronously. Here Callable has a specific usage.

    While for Runnable(0 in 0 out), Supplier(0 in 1 out), Consumer(1 in 0 out) and Function(1 in 1 out), they've been parts of the functional feature since Java 8. All of them are ready to be handled by something lambda friendly, like CompletableFuture. Here Supplier just means a function without any input param but has a return value, which is highly abstract.

提交回复
热议问题