Bug in the compiler I think?

David Conrad drconrad at gmail.com
Wed Jun 27 04:05:49 PDT 2012


On Tue, 26 Jun 2012 09:05:31 -0700, Sam Pullara <sam at sampullara.com> wrote:

>
> ...
>
> Fails to compile due ambiguous target type it appears -- seems like it
> should pick the IntMapper:
>
>    interface Person {
>        int age();
>    }
>    public static void main(String[] args) {
>        List<Person> list = new ArrayList<>();
>        list.sorted(comparing(Person::age));
>    }
>
> src/test/java/spullara/Scratch.java:14: error: no suitable method found for
> comparing(Person#age)
>        list.sorted(comparing(Person::age));
>                    ^
>

cyclic inference, cannot tell the difference between Mapper,
IntMapper, LongMapper, DoubleMapper, yadda, yadda, yadda.

The mappers all take some T as a parameter which needs to be
inferred here. Person::age is nullary, so T is void, or Void. I don't
think it's allowed to disambiguate them by return type, and they're
not distinguishable by parameter types. Ugly. Ugh.

Nice catch. :)

David


More information about the lambda-dev mailing list