I want a CompletableFuture that only signals the completion (eg 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());
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.