reference to comparing is ambiguous & inference loop

Henry Jen henry.jen at oracle.com
Wed Jun 12 23:53:41 PDT 2013


On Jun 12, 2013, at 9:07 PM, Boaz Nahum <boaznahum at gmail.com> wrote:

> Isn't comparingDouble shorter?
> 
> 

We are working to get rid of the cast for most common cases, method reference for example.

Cheers,
Henry
> 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