Interesting inference case
Sam Pullara
spullara at gmail.com
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) {}
@Test
public void test() {
ExecutorService es = Executors.newCachedThreadPool();
es.submit(this::call);
}
}
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.
Sam
More information about the lambda-libs-spec-experts
mailing list