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

Archie Cobbs archie.cobbs at gmail.com
Thu Oct 17 15:03:32 UTC 2024


On Thu, Oct 17, 2024 at 5:34 AM Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:

> Funny to see the FOREACHLOOP popping out. This code is (at least) from 17
> years ago (!!) and predates any form of effectively final analysis - back
> then even for-each required to hoist the variable in a separate final one
> :-)
>

I was wondering about that as well. I didn't realize that there was a point
where foreach() already existed and this effectively final tweak was added.
I don't see a relevant JEP, did it predate the JEP process?


> I realize, the important info is not where the dummy variable is declared.
> It's the declaration of the variable it points to in the initializer that
> matters!
>

D'oh, yes of course... easy to fix though.

Here are the new stats - these look more like what one might expect:

  87 METHODDEF
  11 FORLOOP
   3 TRY
   3 IF
   3 FOREACHLOOP
   3 DOLOOP
   2 WHILELOOP
   1 CASE

Now there are 3 FOREACHLOOP's :)

-Archie

-- 
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20241017/2cded836/attachment.htm>


More information about the amber-dev mailing list