Loss of conciseness due to overload ambiguity
Venkat Subramaniam
venkats at agiledeveloper.com
Wed Jan 9 08:07:01 PST 2013
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