RFR: 8341782: Allow lambda capture of basic for() loop variables as with enhanced for() [v4]
Archie Cobbs
acobbs at openjdk.org
Thu Dec 19 15:23:01 UTC 2024
On Sun, 13 Oct 2024 16:24:41 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:
>> This PR changes the compiler to allow basic `for()` loop iteration variables to be captured by lambdas in the loop body, even when their "effectively final" status is invalidated by modifications in the header of the loop.
>>
>> This allows code like this to compile:
>>
>> for (int i = 1; i <= 3; i++) {
>> Runnable r = () -> System.out.println(i);
>> }
>
> Archie Cobbs has updated the pull request incrementally with one additional commit since the last revision:
>
> Make "effectively final in the loop" work with try-with-resources statements.
We decided not to pursue this; closing this PR.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/21415#issuecomment-2554580182
More information about the compiler-dev
mailing list