Question 4
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Main {
public static void main(String[] args) {
ExecutorService pool = Executors.newSingleThreadExecutor();
Callable<String> job = () -> "done";
pool.execute(job);
pool.shutdown();
}
}
- A Callable cannot return String
- B execute accepts only a Runnable; use submit(job) to run a Callable and get a Future Correct
- C Single-thread executors cannot run Callables
- D shutdown must be called first
Correct Answer: Option B
javac: "incompatible types: Callable
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!