JDK-8300691 - final variables in for loop headers should accept updates

Archie Cobbs archie.cobbs at gmail.com
Wed Dec 11 20:25:08 UTC 2024


Dear Spec Experts,

There is a (small) language change under consideration on amber-dev, and
opinions have been expressed in multiple directions, so I'm turning to this
list for hopefully some authoritative adjudication.

The idea is: allow loop variables declared in basic (old style) for() loops
to be captured in the body of the loop as long as they are not reassigned
in the body of the loop, even though they might be reassigned in the loop
step:

for (int i = 1; i <= 3; i++) {
    Runnable r = () -> System.out.println(i);   // allow this
}

Long discussion starts here (continues into October):
https://mail.openjdk.org/pipermail/amber-dev/2024-September/008921.html

Here's what has been drafted so far (all subject to improvement of course):

Bug: https://bugs.openjdk.org/browse/JDK-8341782
CSR: https://bugs.openjdk.org/browse/JDK-8341783
JEP: https://bugs.openjdk.org/browse/JDK-8341785
JLS: https://bugs.openjdk.org/browse/JDK-8341786
PR: https://github.com/openjdk/jdk/pull/21415

Just to be clear, I know it looks like I've got a lot personally invested
in this, but honestly I don't care about the outcome. Yes I think this
would be a nice tweak, but it's not my decision. Instead, the items listed
above are there to create a tangible basis for making such a decision. I am
really just trying to knock this item off my to-do list one way or the
other (scrubbing the to-do list is a favorite year-end activity).

Let me know your collective thoughts, ideally one of: ▢ Proceed ▢ Reject ▢
Shelve it for later

Thanks!
-Archie

-- 
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-experts/attachments/20241211/4d27d8d7/attachment-0001.htm>


More information about the amber-spec-experts mailing list