Lambda parameters do not use the GLB of the inferred parameter type

Issue #181 resolved
Jesper Öqvist created an issue

ExtendJ 8.0.1-139-gb1294d4 Java SE 8

A lambda expression with an inferred type should use the greatest lower bound (GLB) of the parameter type for the lambda parameter type. For example:


public class Test {
  void m(Stream<String> stream) { -> s.length());

The type of the lambda expression above is Function<? super String, R> and the type of the parameter s should be the GLB, i.e. String, however ExtendJ assigns the type ? super String to s, as evidenced by the error message: error: no method named length() in wildcards.? super java.lang.String matches.

Comments (3)

  1. Jesper Öqvist reporter

    The Java specification seems to describe the type of a lambda expression to be the non-wildcard parameterization of the target function type.

    See JLS 8 §9.9

  2. Jesper Öqvist reporter

    Here is another test case showing the same error more clearly:

    import java.util.function.Function;
    public class Test {
      Function<? super String, Integer> fun = s -> s.length();
  3. Log in to comment