Void is a special class that is used to represent no return value. While there is nothing special about Void
per se, it can't be (and never is) instantiated, so the only possible value for it is always null
. It is used for two things:
- To say that a generic method or class has no return value.
- To represent the
void
return type in Java reflection using Void.TYPE
. See How to determine by reflection if a Method returns 'void' for example.
So it is very different from a wildcard, which is no actual class but represents one specific, unknown type at compile time. At runtime, it is erased like every other generic type.
Regarding the submit
method. Here are the two implementations from JDK 6:
public Future<?> submit(Runnable task) {
if (task == null) throw new NullPointerException();
RunnableFuture<Object> ftask = newTaskFor(task, null);
execute(ftask);
return ftask;
}
and JDK 7:
public Future<?> submit(Runnable task) {
if (task == null) throw new NullPointerException();
RunnableFuture<Void> ftask = newTaskFor(task, null);
execute(ftask);
return ftask;
}
As you can see, the type was changed to Void
only in JDK 7, probably because it makes more sense conceptually. But since the interface of the method could not be changed (for compatibility reasons and because the method implements Future<?> submit(Runnable task)
of the ExecutorService interface), the return type Future<?>
stayed the same. That's my explanation.