The ExecutorService has the following method:
Future<?> submit(Runnable task)
But since this Future
's get
method will always return null
wouldn't the following signature be more appropriate?
Future<Void> submit(Runnable task)
Jdk 1.8 inside submit method implementation void is used while in jdk1.6 it was Object .My understanding is it is more appropriate to use void that's why it is changed in jdk1.7/1.8.Only to support the interface not changing it
public Future<?> submit(Runnable task) {
if (task == null) throw new NullPointerException();
RunnableFuture<Void> ftask = newTaskFor(task, null);
execute(ftask);
return ftask;
}
and in JDK 1.6
public Future<?> submit(Runnable task) {
if (task == null) throw new NullPointerException();
RunnableFuture<Object> ftask = newTaskFor(task, null);
execute(ftask);
return ftask;
}
Notice that Runnable
's run
method returns void
primitive and not Void
type. For that reason, Future
cannot have a Void
type and the solution was to make it a wildcard. Note that Future
is from java 1.5 whereas Runnable
is from 1.0. They wouldn't change run
's return type to conform to the Future
due to legacy code reasons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With