Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of these is the correct signature of ExecutorService.submit for a Callable?

  • A.<T> T submit(Callable<T> task)
  • B.void submit(Callable task)
  • C.Future submit(Runnable task, Callable result)
  • D.<T> Future<T> submit(Callable<T> task)

Answer: D

Correct answer: <T> Future<T> submit(Callable<T> task)

Submission is asynchronous, so the method returns immediately with a Future standing for the eventual result rather than the result itself. The type parameter ties the future’s type to the callable’s, so get() returns the right type without a cast.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.