"more specific method" w.r.t function return type

Zhong Yu zhong.j.yu at gmail.com
Tue Dec 17 16:16:15 PST 2013


On Tue, Dec 17, 2013 at 6:06 PM, Zhong Yu <zhong.j.yu at gmail.com> wrote:
> The following code does not compile in jdk8b120
>
> public class Tmp
> {
>     <T> void foo(Function<String,T> function){}
>
>     void foo(Consumer<String> consumer){}
>
>     void test()
>     {
>         foo( s->System::gc ); // javac: foo is ambiguous

sorry, what I meant was

        foo( s->System.gc() ); // javac: foo is ambiguous

>     }
> }
>
> however I think that foo#1 should be more specific than foo#2, because
> Consumer returns void.
>
> Is this a javac bug or my understanding is incorrect?
>
> (If foo#1 is indeed the most specific method, the code still won't
> compile because gc() returns void)
>
> Zhong Yu


More information about the lambda-dev mailing list