Reputation: 3543
I want a CompletableFuture that only signals the completion (e.g. I don't have a return value).
I can instantiate the CompletableFuture as:
CompletableFuture<Void> future = new CompletableFuture<> ();
But what should I feed into the complete method? For example, I can't do
future.complete(new Void());
Upvotes: 29
Views: 18840
Reputation: 594
A bit shorter (and more elegant) way to write it would be:
return CompletableFuture.completedFuture(null);
Upvotes: 3
Reputation: 311228
As you've noticed, you cannot instantiate a Void
object like this.
Since you don't care about the future's value, you could just complete it with null
:
future.complete(null);
Upvotes: 38