reference to comparing is ambiguous & inference loop
Henry Jen
henry.jen at oracle.com
Wed Jun 12 12:49:13 PDT 2013
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