CompletableFuture already completed with an exception

前端 未结 2 1050
时光说笑
时光说笑 2020-12-01 18:27

CompletableFuture.completedFuture() returns a CompletedFuture that is already completed with the given value.

How do we construct a CompletableFut

2条回答
  •  广开言路
    2020-12-01 18:53

    Unlike Java 9 and later, Java 8 does not provide a static factory method for this scenario. The default constructor can be used instead:

    CompletableFuture future = new CompletableFuture<>();
    future.completeExceptionally(exception);
    

提交回复
热议问题