RFR: 8341782: Allow lamba capture of basic for() loop variables as with enhanced for()
Rémi Forax
forax at openjdk.org
Wed Oct 9 07:45:56 UTC 2024
On Tue, 8 Oct 2024 19:53:56 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);
> }
That's the curse of small language improvements, there is always a bigger one more important to spec/implement.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/21415#issuecomment-2401577660
More information about the compiler-dev
mailing list