The following code compiles with javac, and with Eclipse 4.6.1/4.6, but produces an error in Eclipse 4.6.2:
package ecbug;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Foo
{
class A
{
public int getStart() { return 0; }
}
void someMethod(List<A> toRemove)
{
Collections.sort(toRemove, Comparator.comparing(t -> -t.getStart()));
}
}
Eclipse 4.6.2 complains, under -t.getStart()
, that there is a Type mismatch: cannot convert from int to Comparable<? super Comparable<? super U>>.
I would think that the arguments to Comparator.comparing(...)
should be a Comparable<T>
with T = A
, with functional method compareTo which returns int
. Eclipse seems to believe that the lambda function should return Comparable<? super Comparable<? super U>>, however.
I strongly suspect an Eclipse bug, but there are certainly cases where Eclipse has correctly implemented the language specification and javac hasn't, so it seems worth asking: is this an Eclipse bug or a javac bug? Can any language-lawyers out there point out the relevant parts of the language spec?
Possibly related questions, which in my eyes are not duplicates:
Java 8 Stream flatMap and group by code compiler error - similar error message, but unclear if it is exactly the same issue; Answer claims that it is an Eclipse bug but provides no bug link nor JLS quotations; refers to old Eclipse version.
Why didn't this java 8 example using type inference compile in Eclipse? - similar to previous
Java Stream collect after flatMap returns List<Object> instead of List<String> - again, may be a different issue; comments claim Eclipse problem but do not justify via reference to JLS nor provide a link to an Eclipse bug report.