Looking at the javadocs it just says
<T> Future<T> submit(Runnable task, T result)Submits a Runnable task for execution and returns a Future representing that task. The Future’s get method will return the given result upon successful completion.
Parameters:
task – the task to submit
result – the result to return
but what does it do with result? does it store anything there? does it just use the type of result to specify the type of Future<T>?
It doesn’t do anything with the result – just holds it. When the task successfully completes, calling
future.get()will return the result you passed in.Here is the source code of Executors$RunnableAdapter, which shows that after the task has run, the original result is returned:
And yes, the generic type of the result should match that of the returned Future.