I want to write an asynchronous method that returns a CompletableFuture
. The only purpose of the future is to track when the method is complete, not its result. Would it be better to return CompletableFuture<Void>
or CompletableFuture<?>
? Is there a reason to prefer one or the other, or are they interchangeable?
CompletableFuture
itself returnsCompletableFuture<Void>
from many of its methods.java.nio
has aFuture<Void>
inAsynchronousSocketChannel
:Future<Void> connect(SocketAddress remote)
.- On the other hand,
java.util.concurrent
classes likeExecutorService
andScheduledExecutorService
returnFuture<?>
: for instance, withFuture<?> submit(Runnable task)
.
Note that I'm only asking about return types, not parameter lists, variable declarations, or other contexts.