Comparators.comparing inference error

Michael Nascimento misterm at
Thu Apr 18 11:18:24 PDT 2013

Hi folks,

I had a comparison chain in Guava which I tried to migrate by creating
a comparator:

Comparator<YearMonthDecade> c = Comparators

getYearMonth returns a YearMonth and getDecadeNumber returns an int. I
get the following compiler error:[69,4] error: reference to comparing is ambiguous
  both method <T#1>comparing(ToLongFunction<? super T#1>) in
Comparators and method <T#2>comparing(ToDoubleFunction<? super T#2>)
in Comparators match
  where T#1,T#2 are type-variables:
    T#1 extends Object declared in method
<T#1>comparing(ToLongFunction<? super T#1>)
    T#2 extends Object declared in method
<T#2>comparing(ToDoubleFunction<? super T#2>)[69,14] error: incompatible types: Cannot
instantiate inference variables T because of an inference loop

I can get it to compile with:

Comparator<YearMonthDecade> c = Comparators

Do you plan to make this work somehow (smarter compiler or no
overloading anymore)?


More information about the lambda-dev mailing list