RFR: 8369517: Compilation mismatch for equivalent lambda and method reference [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Fri Oct 10 13:19:35 UTC 2025


On Thu, 9 Oct 2025 23:33:43 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)
>
> Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:
> 
>   fixing issues

The fix looks good!

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

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

The original test from Tagir was slightly different -- maybe we want to use that one instead?

I think it was `return create(...).self()`

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

Marked as reviewed by mcimadamore (Reviewer).

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


More information about the compiler-dev mailing list