What is the correct way to create an already-completed CompletableFuture

Since Void can not be instantiated, you can only complete a CompletableFuture<Void> with a null result, which is exactly what you also will get when calling join() on the future returned by allOf() once it has been successfully completed.

So you can use

CompletableFuture<Void> cf = CompletableFuture.completedFuture(null);

to get such an already completed future.

But you can also use

CompletableFuture<Void> cf = CompletableFuture.allOf();

to denote that there are no jobs the result depends on. The result will be exactly the same.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)