RFR: 8369517: Compilation mismatch for equivalent lambda and method reference

Chen Liang liach at openjdk.org
Thu Oct 9 22:17:03 UTC 2025


On Thu, 9 Oct 2025 19:26:36 GMT, Vicente Romero <vromero at openjdk.org> wrote:

> 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)

Changes requested by liach (Reviewer).

test/langtools/tools/javac/lambda/methodReference/ResultTypeNotBeingCapturedTest.java line 43:

> 41: 
> 42:     static X<X<?>> methodRef() {
> 43:         var s = (String)create(Main::makeX);

Suggestion:

        var s = (String)create(ResultTypeNotBeingCapturedTest::makeX);

Please also update the .out output, which should be more consistent after this fix.

-------------

PR Review: https://git.openjdk.org/jdk/pull/27737#pullrequestreview-3320789875
PR Review Comment: https://git.openjdk.org/jdk/pull/27737#discussion_r2418071341


More information about the compiler-dev mailing list