Bug in the compiler I think?
Sam Pullara
sam at sampullara.com
Tue Jun 26 09:05:31 PDT 2012
Couple of bugs in the current implementation (b35,
fe85a4795f427886d8e572032b1c4b7df3085d68):
Fails: Lazy<String> lazyString = *new Lazy<>*(() -> "Value: " +
ai.incrementAndGet());
Works: Lazy<String> lazyString = *new Lazy<String>*(() -> "Value: " +
ai.incrementAndGet());
Fails to compile due ambiguous target type it appears -- seems like it
should pick the IntMapper:
interface Person {
int age();
}
public static void main(String[] args) {
List<Person> list = new ArrayList<>();
list.sorted(comparing(Person::age));
}
src/test/java/spullara/Scratch.java:14: error: no suitable method found for
comparing(Person#age)
list.sorted(comparing(Person::age));
^
method Comparators.<T#1,U>comparing(Mapper<T#1,U>) is not applicable
(cyclic inference - cannot infer target type for given lambda/method
reference expression)
method Comparators.<T#2>comparing(IntMapper<T#2>) is not applicable
(cyclic inference - cannot infer target type for given lambda/method
reference expression)
method Comparators.<T#3>comparing(LongMapper<T#3>) is not applicable
(cyclic inference - cannot infer target type for given lambda/method
reference expression)
method Comparators.<T#4>comparing(DoubleMapper<T#4>) is not applicable
(cyclic inference - cannot infer target type for given lambda/method
reference expression)
where T#1,U,T#2,T#3,T#4 are type-variables:
T#1 extends Object declared in method <T#1,U>comparing(Mapper<T#1,U>)
U extends Comparable<? super U> declared in method
<T#1,U>comparing(Mapper<T#1,U>)
T#2 extends Object declared in method <T#2>comparing(IntMapper<T#2>)
T#3 extends Object declared in method <T#3>comparing(LongMapper<T#3>)
T#4 extends Object declared in method <T#4>comparing(DoubleMapper<T#4>)
1 error
Sam
More information about the lambda-dev
mailing list