Quantcast
Viewing all articles
Browse latest Browse all 3

Choosing between overloaded methods if actual parameter is a lambda

In Java 1.8, the following lambda expression complies with both Runnable and Callable functional interfaces:

() -> {
    throw new RuntimeException("FIXME");
}

Still, if I submit it to an ExecutorService using a single-argument method, and ignore the return value (i. e. no type inference information is available), ExecutorService#submit(Callable) is chosen at compile time, unless I explicitly cast my lambda to Runnable.

How does the compiler choose between overloaded methods in the above case, provided that Runnable and Callable don't share any common hierarchy and most specific type rule doesn't apply here?


Viewing all articles
Browse latest Browse all 3

Trending Articles