Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8030012

Lambda Spec: Allow assignment conversion of lambda results during inference

XMLWordPrintable

    • Verified

      Result expressions in lambda bodies are required to be _assignable_ to the targeted return type. For a constant expression, this may involve a narrowing primitive conversion.

      If the lambda expression is an invocation argument, and the target type mentions an inference variable, the current spec text requires _invocation compatibility_, which does not allow a narrowing primitive conversion.

      Example:

      interface ByteFunction<T> {
        byte apply(T arg);
      }

      <T> void m(ByteFunction<T> f) {}

      ByteFunction<String> f = s -> 100; // no error
      m(s -> 100); // expected: no error; specified: error

      javac already seems to behave correctly here.

            dlsmith Dan Smith
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: