Interesting inference case

Sam Pullara spullara at
Mon Sep 2 10:19:05 PDT 2013

I was trying to pass Semaphore::release to ExecutorService.submit and ran into a puzzling compile error. Here is a reproduction case:

public class InferTest {
    void call() {}
//    void call(int i) {}

    public void test() {
        ExecutorService es = Executors.newCachedThreadPool();

With the comment, this compiles fine. If you uncomment the second call() method it fails with:

java: reference to submit is ambiguous
  both method <T>submit(java.util.concurrent.Callable<T>) in java.util.concurrent.ExecutorService and method submit(java.lang.Runnable) in java.util.concurrent.ExecutorService match
java: incompatible types: cannot infer type-variable(s) T
    (argument mismatch; bad return type in method reference
      void cannot be converted to T)

I'm not sure why the overload on call() would cause the ambiguity. 


More information about the lambda-libs-spec-observers mailing list