RFR: 8341782: Allow lambda capture of basic for() loop variables as with enhanced for() [v2]

Archie Cobbs acobbs at openjdk.org
Thu Oct 10 23:45:45 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:

  Fix bug pointed out by Maurizio & do some other cleanup.

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/21415/files
  - new: https://git.openjdk.org/jdk/pull/21415/files/1a5859d9..00181f7f

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=21415&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=21415&range=00-01

  Stats: 64 lines in 3 files changed: 30 ins; 12 del; 22 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