reference to comparing is ambiguous & inference loop
Boaz Nahum
boaznahum at gmail.com
Wed Jun 12 21:07:24 PDT 2013
Isn't comparingDouble shorter?
Thanks
Boaz
On Jun 12, 2013 10:49 PM, "Henry Jen" <henry.jen at oracle.com> wrote:
> On Jun 12, 2013, at 12:20 PM, Boaz Nahum <boaznahum at gmail.com> wrote:
>
> > I built lambda/lambda today
> >
> >
> >
> > class TestResult {
> > public double getRank() { ... }
> > }
> >
> > List<TestResult> results = ..
> > results.sort(Comparator.comparing(TestResult::getRank));
> >
> > Got this error:
> > java: reference to comparing is ambiguous
> > both method <T>comparing(java.util.function.ToLongFunction<? super T>)
> in
> > java.util.Comparator and method
> > <T>comparing(java.util.function.ToDoubleFunction<? super T>) in
> > java.util.Comparator match
> >
> > java: incompatible types: Cannot instantiate inference variables T
> because
> > of an inference loop
> >
> >
> > Any way to get around this ?
> >
>
> Compiler is looking to improve this, add a cast for now.
>
> (ToDoubleFunction<TestResult>) TestResult::getRank.
>
> Cheers,
> Henry
>
>
More information about the lambda-dev
mailing list