RFR: 8341782: Allow lambda capture of basic for() loop variables as with enhanced for() [v4]
Archie Cobbs
acobbs at openjdk.org
Sun Oct 13 16:24:41 UTC 2024
> 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.
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/21415/files
- new: https://git.openjdk.org/jdk/pull/21415/files/76d5c5e7..9494473a
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=21415&range=03
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=21415&range=02-03
Stats: 19 lines in 2 files changed: 17 ins; 0 del; 2 mod
Patch: https://git.openjdk.org/jdk/pull/21415.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/21415/head:pull/21415
PR: https://git.openjdk.org/jdk/pull/21415
More information about the compiler-dev
mailing list