The following code compiles fine in IntelliJ and Eclipse, but the JDK compiler 1.8.0_25 complains. First, the code.
import java.util.function.Predicate;
public abstract class MyStream<E> {
static <T> MyStream<T> create() {
return null;
}
abstract MyStream<E> filter(MyPredicate<? super E> predicate);
public interface MyPredicate<T> extends Predicate<T> {
@Override
boolean test(T t);
}
public void demo() {
MyStream.<Boolean> create().filter(b -> b);
MyStream.<String> create().filter(s -> s != null);
}
}
The output from javac 1.8.0_25 is:
MyStream.java:18: error: incompatible types: incompatible parameter types in lambda expression
MyStream.<Boolean> create().filter(b -> b);
^
MyStream.java:18: error: incompatible types: bad return type in lambda expression
MyStream.<Boolean> create().filter(b -> b);
^
? super Boolean cannot be converted to boolean
MyStream.java:19: error: bad operand types for binary operator '!='
MyStream.<String> create().filter(s -> s != null);
^
first type: ? super String
second type: <null>
MyStream.java:19: error: incompatible types: incompatible parameter types in lambda expression
MyStream.<String> create().filter(s -> s != null);
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
4 errors
When I replace ? super E
with simply E
, JDK compiles successfully.
When I replace filter(MyPredicate
with filter(Predicate
, JDK compiles successfully.
Since it works with JDK 1.8.0_60, I suspect it is a compiler bug.
Any details on what caused this and when it has been fixed?