Loss of conciseness due to overload ambiguity
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Wed Jan 9 08:45:18 PST 2013
We are considering ways to mitigate this; if the method reference is
unambiguous (only one match) there are facts that can be used to achieve
more overload resolution precision (pretty much what we do with implicit
lambdas - where we use arity to prune unwanted candidates).
Maurizio
On 09/01/13 17:07, Venkat Subramaniam wrote:
> Greetings,
>
> Is there a way to gain the desired conciseness in the following case?
>
> List<Person> people = Arrays.asList(
> new Person("Kate", 10),
> new Person("Jack", 10)
> );
>
> Function<Person, String> byName = person -> person.getName();
>
> people.stream().sorted(comparing(byName)).into(new ArrayList<>());
> //[Jack - 10, Kate - 10]
>
> people.stream().sorted(comparing(Person::getName)).into(new ArrayList<>());
>
> /*
> error: reference to comparing is ambiguous
> people.stream().sorted(comparing(Person::getName)).into(new ArrayList<>());
> ^
> both method <T#1>comparing(IntFunction<? super T#1>) in Comparators and method <T#2,U>comparing(Function<? super T#2,? extends U>) in Comparators match
> where T#1,T#2,U are type-variables:
> T#1 extends Object declared in method <T#1>comparing(IntFunction<? super T#1>)
> T#2 extends Object declared in method <T#2,U>comparing(Function<? super T#2,? extends U>)
> U extends Comparable<? super U> declared in method <T#2,U>comparing(Function<? super T#2,? extends U>)
> 1 error
>
> */
>
> Thanks,
>
> Venkat
>
More information about the lambda-dev
mailing list