Overload issue - more-specific-ness
Zhong Yu
zhong.j.yu at gmail.com
Thu Mar 13 23:48:12 UTC 2014
Consider this program:
// like Runnable, but throws
interface RunnableX extends Callable<Void>
{
void run() throws Exception;
default Void call() throws Exception
{
run();
return null;
}
}
static void foo(RunnableX r){}
static void foo(Callable<List<?>> c){}
The overload should be fine, because both functional interfaces are
0-arg. And foo#2 should be more specific than foo#1.
However the following program fails to compile
public void test()
{
foo( ()->new ArrayList<Void>() );
// javac: reference to foo is ambiguous
// both method foo(RunnableX) and method foo(Callable<List<?>>) match
}
Is it the correct behavior or a bug? It seems to me that foo#2 should
be the most-specific method here.
( If RunnableX does NOT extend Callable<Void>, the program compiles.)
Thanks,
Zhong Yu
More information about the lambda-dev
mailing list