<div dir="ltr"><div class="gmail_default" style="font-family:monospace">I am in the camp of "do it all, or don't do it at all."<br><br>Either this "quiescent" functionality elevates past for-loops and becomes available to ALL local variables, or this just shouldn't be done at all. For-loops (even loops in general) happen to be the most obvious pain point, but they certainly aren't the only one.<br><br>That said, even if we apply this quiescent functionality to all local variables, we would only be scratching the surface of the REAL problem -- CORRECTLY outlining when and where it is TRULY SAFE to use a variable's value.<br><br>The entire reason that this feature is being considered is because WE KNOW that we are being safe, but the compiler doesn't have enough info to know. The rules for safety do not align with what is TRULY SAFE. So much so, that even beginner's to this language can see the excessiveness of the rules here.<br><br>Here is an example of what I mean when I say we are only scratching the surface.<br><br><a href="https://stackoverflow.com/questions/75072937/why-does-my-lambda-get-illegal-forward-reference-but-my-anonymous-class-does-no">https://stackoverflow.com/questions/75072937/why-does-my-lambda-get-illegal-forward-reference-but-my-anonymous-class-does-no</a><br><br>This also bumps shoulders with your "before super()" work Archie.<br><br>We intuitively "know" that something like this should be possible, but the language doesn't expose any way of doing this without some level of indirection, duplication, or assignment after the fact. Just like a dummy variable for for-loops.</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, Dec 10, 2024 at 1:31 PM Tagir Valeev <<a href="mailto:amaembo@gmail.com">amaembo@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>Hello! <div dir="auto"><br></div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Dec 10, 2024, 18:57 Archie Cobbs <<a href="mailto:archie.cobbs@gmail.com" target="_blank">archie.cobbs@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Fri, Oct 25, 2024 at 10:02 AM Archie Cobbs <<a href="mailto:archie.cobbs@gmail.com" rel="noreferrer" target="_blank">archie.cobbs@gmail.com</a>> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div>Is there some quasi-consensus to go forward with this idea for fixing basic for() loops?</div></div></div></blockquote><div><br></div><div>(Hmm, nobody responded yes and nobody responded no...)<br></div></div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Just for the record: I previously said that I don't think we should salvage classic for loop, because it's awful. Instead, we should invest into adding first-class ranges to Java, or at least library support, to be able to write something like</div><div dir="auto"><br></div><div dir="auto">for(int i: rangeClosed(1, 3)) {</div><div dir="auto">...</div><div dir="auto">}</div><div dir="auto"><br></div><div dir="auto">This way, the lambda problem will be solved automatically, and people will get much more readable and much less errorprone way to iterate over integers.</div><div dir="auto"><br></div><div dir="auto">I still stick to this point of view.</div><div dir="auto"><br></div><div dir="auto">With best regards, </div><div dir="auto">Tagir Valeev</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div></div><div><br></div><div>Now that JDK 24 is out of the way, I'd like to get some kind of final adjudication on whether to continue pursuing this idea from this list.</div><div><div><br></div><div>If everyone is good with doing this then I'm happy to continue working on it, otherwise I'm happy to 
shelve it. I would just like to tie up the loose end one way or another.<br></div><div><br></div></div><div>To recap: the idea is to 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 (but they may be reassigned in the loop step). For example:</div><div style="margin-left:40px"><pre><span>for</span> (<span>int</span> <span>i</span> = <span>1</span>; <span>i</span> <= <span>3</span>; <span>i</span>++) {
    <span>Runnable</span> <span>r</span> = () -> <span>System</span>.<span>out</span>.<span>println</span>(i);   // allow this
}</pre></div><div><div>There was lots of good discussion and we did narrow down the idea to what's described above. However I'm unclear on whether to now proceed with asking for additional reviews, etc. and don't want to presume.</div><div><br></div><div>If nobody replies I won't ask again :)<br></div><br><div>FWIW here's what has been drafted so far (all subject to improvement of course):<br></div><div><br></div><div>Bug: <a href="https://bugs.openjdk.org/browse/JDK-8341782" rel="noreferrer" target="_blank">https://bugs.openjdk.org/browse/JDK-8341782</a></div><div>CSR: <a href="https://bugs.openjdk.org/browse/JDK-8341783" rel="noreferrer" target="_blank">https://bugs.openjdk.org/browse/JDK-8341783</a><br>JEP: <a href="https://bugs.openjdk.org/browse/JDK-8341785" rel="noreferrer" target="_blank">https://bugs.openjdk.org/browse/JDK-8341785</a><br>JLS: <a href="https://bugs.openjdk.org/browse/JDK-8341786" rel="noreferrer" target="_blank">https://bugs.openjdk.org/browse/JDK-8341786</a><br>PR: <a href="https://github.com/openjdk/jdk/pull/21415" rel="noreferrer" target="_blank">https://github.com/openjdk/jdk/pull/21415</a></div><div><br></div><div>Thanks,</div><div>-Archie</div><div><br></div></div></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>
</blockquote></div></div></div>
</blockquote></div>