JDK-8300691 - final variables in for loop headers should accept updates
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Oct 17 15:08:41 UTC 2024
On 17/10/2024 16:03, Archie Cobbs wrote:
> 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?
Effectively final support was added as part of Java 8 and Project
Lambda. Java 7 also had some bits of effective finality here and there,
but Java 8 is what sealed the deal. Back then we did not have 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.
Thanks
>
> 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 :)
Yowza! For each gained more than the regular loop :-)
Maurizio
>
> -Archie
>
> --
> Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20241017/ae835081/attachment.htm>
More information about the amber-dev
mailing list