Release Note: Compilation Mismatch for Equivalent Lambda and Method Reference

XMLWordPrintable

    • Type: Sub-task
    • Resolution: Delivered
    • Priority: P4
    • 26
    • Affects Version/s: 26
    • Component/s: tools

      Prior to JDK 26, the `javac` compiler did not apply a JLS mandated capture conversion when deciding if a method reference is compatible with a given function type. This could lead the `javac` compiler to accept code like the following:

      ```
          import java.util.function.Supplier;

          class Test {
              interface X<T> {
                  X<T> self();
              }
              static X<?> makeX() {return null;}
              static <R> X<R> create(Supplier<? extends R> supplier) {return null;}
              static X<X<?>> methodRef() {
                  return create(Test::makeX).self();
              }
          }
      ```

      Starting from JDK 26, the `javac` compiler will apply the JLS mandated capture conversion when deciding if a method reference is compatible with a given function type. Code, like that in the sample above, will be rejected.

            Assignee:
            Vicente Arturo Romero Zaldivar
            Reporter:
            Vicente Arturo Romero Zaldivar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: