bad return type in lambda expression
10:53 12 Oct 2015

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 {

  static  MyStream create() {
    return null;
  }

  abstract MyStream filter(MyPredicate predicate);

  public interface MyPredicate extends Predicate {

    @Override
    boolean test(T t);
  }

  public void demo() {
    MyStream. create().filter(b -> b);
    MyStream. 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. create().filter(b -> b);
                                       ^
MyStream.java:18: error: incompatible types: bad return type in lambda expression
    MyStream. create().filter(b -> b);
                                            ^
    ? super Boolean cannot be converted to boolean
MyStream.java:19: error: bad operand types for binary operator '!='
    MyStream. create().filter(s -> s != null);
                                             ^
  first type:  ? super String
  second type: 
MyStream.java:19: error: incompatible types: incompatible parameter types in lambda expression
    MyStream. 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?

java lambda java-8