Scrivio Interview library
DebuggingFoundations7 min read · updated 12 November 2026

ExecutorService.submit is overloaded for Runnable and Callable. Which overload does each call use, and does each compile? (a) ex.submit(() -> doWork()) where doWork returns void; (b) ex.submit(() -> compute()) where compute returns int; (c) ex.submit(() -> { Files.delete(path); }) where Files.delete throws IOException.

(a) compiles and uses submit(Runnable), because a lambda whose body is a void method call can only be void-compatible. (b) compiles and uses submit(Callable<Integer>): an expression lambda that calls a value-returning method fits both interfaces, and the compiler prefers Callable as more specific because its method returns a value. (c) does not compile: a block with no return statement fits only Runnable, and Runnable.run() cannot throw IOException; adding return null; makes it a Callable, or we handle the exception inside the lambda.

Why this question is asked

ExecutorService.submit is one of the first places where many developers meet lambda overload resolution, usually through a confusing compile error or a Future that holds null when they expected a value. Interviewers ask this question because the three small cases cover the rules that decide which functional interface a lambda becomes: void-compatible and value-compatible bodies, the most specific overload, and checked exceptions. In this answer, we will recap the two overloads, learn the two compatibility rules, walk through each case with the compiler's reasoning, fix case (c) two ways, and end with the lesson for our own API design.

1A Quick Recap of the Two Overloads

ExecutorService has two one-argument submit methods. submit(Runnable task) takes a Runnable, whose method is void run() and declares no checked exceptions; it returns a Future<?> whose get() returns null when the task finishes. submit(Callable<T> task) takes a Callable, whose method is T call() throws Exception; it returns a Future<T> holding the value call() returned.

Both Runnable and Callable are functional interfaces with zero parameters, so any zero-argument lambda is a candidate for both. The compiler must decide which one each lambda can be, and, if it can be both, which to prefer.

2Void-Compatible and Value-Compatible Lambdas

The Java Language Specification classifies a lambda body by shape. A lambda is void-compatible if it can implement a method that returns void, and value-compatible if it can implement a method that returns a value.

For an expression lambda, the body is a single expression. If that expression is something that can stand alone as a statement, such as a method call, the lambda is void-compatible, because the value can simply be thrown away. If the expression has a non-void type, it is also value-compatible. So () -> compute() is both, while () -> doWork() with a void method is only void-compatible, and () -> 42 is only value-compatible, because 42; is not a legal statement.

For a block lambda, the return statements decide. A block where no return statement has a value, and that can finish normally, is void-compatible only. A block where every path ends in return with a value, or a throw, is value-compatible only. A block that can do both does not compile.

Which interfaces each lambda fits
LambdaVoid-compatibleValue-compatibleFits
() -> doWork() // voidyesnoRunnable only
() -> compute() // intyesyesboth
() -> 42noyesCallable only
() -> { Files.delete(path); }yesnoRunnable only
() -> { Files.delete(path); return null; }noyesCallable only

3Walking Through the Three Calls

Now we can follow the compiler's reasoning for each call.

Java
ExecutorService ex = Executors.newFixedThreadPool(2);
// (a) doWork() returns void
Future<?> a = ex.submit(() -> doWork()); // submit(Runnable)
System.out.println(a.get()); // null
// (b) compute() returns int
Future<Integer> b = ex.submit(() -> compute()); // submit(Callable<Integer>)
System.out.println(b.get()); // 42, the value compute() returned
// (c) Files.delete throws IOException
ex.submit(() -> { Files.delete(path); });
// error: unreported exception IOException; must be caught or declared to be thrown
Step throughHow the compiler picks a submit overload
  1. Classify the lambda bodyvoid-compatible, value-compatible or both
  2. Fits both Runnable and Callable?
    YesPrefer Callable: its method returns a valueNoUse the only one that fits
  3. Does the body throw a checked exception the chosen method does not declare?
    YesCompile errorNoCompiles

3 steps in order. Play them, or step through them one at a time.

In case (a), the body is a call to a void method. It cannot produce a value, so the lambda is not value-compatible and Callable is not applicable. Only submit(Runnable) remains, and it compiles. The returned Future gives null.

In case (b), the lambda fits both overloads, so both are applicable and the compiler looks for the most specific one. For lambdas with explicitly typed parameters (a lambda with zero parameters counts as one), the rule says an interface whose method returns a value is more specific than one whose method returns void. So Callable<T> wins, T is inferred as Integer, and the int result is boxed. If we wanted to ignore the result, we would still get a Future<Integer>, which is harmless.

In case (c), the block has no return with a value, so it is void-compatible only, and only submit(Runnable) is applicable. The compiler picks it and then checks the body against Runnable.run(), which declares no checked exceptions. Files.delete throws IOException, a checked exception, so we get the unreported exception error. Notice that the compiler never falls back to Callable here, even though Callable.call() would allow the exception. Applicability is decided by the shape of the body, and exceptions are checked only after the method is chosen.

4Fixing Case (c)

There are two clean fixes, and they produce different behaviour, so we pick the one that matches what we want.

Java
// Fix 1: make the lambda value-compatible, so it becomes a Callable
Future<Object> f1 = ex.submit(() -> { Files.delete(path); return null; });
// Callable.call() throws Exception, so IOException is allowed
f1.get(); // if the delete failed: ExecutionException with cause NoSuchFileException
// Fix 2: handle the exception inside the lambda, keeping it a Runnable
Future<?> f2 = ex.submit(() -> {
try {
Files.delete(path);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
f2.get(); // if the delete failed: ExecutionException with cause UncheckedIOException

Fix 1 is the shortest and keeps the original IOException as the cause, which is useful when the caller inspects the Future. Its return null; is a little odd to read, so a short comment helps. Fix 2 keeps the task a Runnable and makes the failure explicit; it is the natural choice if we want to log, retry or translate the error inside the task. In both cases, the exception does not disappear: it is captured in the Future and rethrown, wrapped in ExecutionException, when someone calls get().

5The Lesson for Our Own APIs

The surprises here come from one design choice: overloading a method on two functional interfaces with the same number of parameters. Readers cannot see which overload a lambda picks without knowing the compatibility rules, and a small edit to the body, such as removing a return statement, silently switches overloads or breaks compilation.

In our own APIs we avoid that. If we need both kinds of task, we give the methods different names, such as run(Runnable) and call(Callable<T>), or accept only one interface. When we must call an existing overloaded API, a cast such as (Callable<Void>) or an explicitly named variable makes the choice obvious to the reader.

6Follow-up questions

Why does case (b) not report an ambiguity?

Because both overloads are applicable and the specification gives a rule for choosing between them. For a lambda with explicitly typed parameters, a functional interface whose method returns a value is more specific than one returning void. That rule exists precisely so that calls like submit(() -> compute()) resolve to Callable.

What happens to an exception thrown inside a Runnable passed to submit?

It is caught by the executor and stored in the Future. Nothing is printed. If nobody calls get(), the failure is silently lost, which is a common production bug. With execute(Runnable) instead of submit, the exception reaches the thread's uncaught exception handler and is usually logged.

Would a method reference behave the same way?

Yes. ex.submit(this::compute) also fits both interfaces and chooses Callable, and ex.submit(this::doWork) with a void method chooses Runnable. A method reference to a method that throws a checked exception fits Callable only if Runnable is not applicable, and the same exception check applies after the choice.

7Conclusion

In this answer, we saw that the compiler decides which submit overload a lambda uses from the shape of its body. A void method call is only void-compatible, so case (a) becomes a Runnable. A call to a value-returning method is both void- and value-compatible, and Callable is chosen as more specific, so case (b) returns a Future<Integer>. A block without a return value is Runnable only, so case (c) fails because run() cannot throw IOException. Adding return null; or handling the exception fixes it, and avoiding overloads on different functional interfaces keeps our own APIs free of these surprises.

What to say in the interviewAbout 90 seconds aloud

Open with

The key is how the compiler classifies a lambda body. An expression lambda whose expression is a method call is void-compatible, because the result can be discarded, and it is also value-compatible if the method returns something.

Then, if they want more

A block lambda is void-compatible if it has no return with a value, and value-compatible if every path returns a value. So in (a), doWork returns void, the lambda is only void-compatible, Callable does not apply, and submit(Runnable) is used; it compiles and the Future's get returns null. In (b), compute returns int, so the lambda fits both.

Both overloads are applicable, and the rule for choosing the most specific one says an interface whose method returns a value beats one returning void, so submit(Callable<Integer>) is chosen and I get a Future<Integer>. In (c), the block has no return, so it fits only Runnable.

The compiler picks Runnable, then checks the body, and since run declares no checked exceptions, Files.delete's IOException gives an unreported exception error. It never falls back to Callable. To fix it, I either add return null so the lambda becomes a Callable, whose call throws Exception, or catch the IOException inside and wrap it in UncheckedIOException.

In my own APIs I avoid overloading on different functional interfaces, because these rules surprise readers.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "ExecutorService.submit is overloaded for Runnable and Callable. Which overload does each...": https://scrivio-interview-library.netlify.app/java/lambdas/7831dc1d46/