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

Compilation mismatch for equivalent lambda and method reference

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • 26
    • 25, 26
    • tools
    • None

      Given the following test case:

      ```
      import java.util.function.Supplier;
      interface Main {
          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(Main::makeX).self();
          }

          static X<X<?>> lambda() {
              return create(() -> makeX()).self();
          }
      }
      ```

      javac reports an error for the method reference but not for the lambda. There should be no difference here (error in both cases)

      reported by Tagir at: https://mail.openjdk.org/pipermail/compiler-dev/2025-October/031680.html

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

              Created:
              Updated: