<div dir="ltr"><div>I think, if we want to find a problem to solve (already kinda starts bad), then that example is not really the best, because either I can see that it is the last use, if for some reason, this is a complicated method, then you can likely refactor the subsequent part into a separate method to make it cleaner. That is, in that example, the "forget" or "last use" (or whatever alternative name it would go by) is just trying to save on code cleanup (not the best thing to promote imho).</div><div><br></div><div>If we need a problem to be solved, then it is usually because you have a parameter which you normalize, and now people should not use the old one. That is, you want to shade the old variable. I don't think "forget" is a good way to address this problem. And normally, you can still factor out the last part into a separate method easily.</div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">Archie Cobbs <<a href="mailto:archie.cobbs@gmail.com">archie.cobbs@gmail.com</a>> ezt írta (időpont: 2026. jan. 27., K, 17:32):<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>I feel the need to push back a little bit against the idea-bashing here... </div><div><br></div><div>I completely agree that adding a new "forget" keyword to the Java language doesn't meet the required cost/benefit standard.</div><div><br></div><div>However that's a separate criticism from the underlying goal, which I like - i.e., help simplify the mental accounting that developers must juggle in their heads.</div><div><br></div><div>If I am looking at a method that starts like this:</div><div><br></div><div style="margin-left:40px"><span style="font-family:monospace">void method() {</span></div><div style="margin-left:40px"><span style="font-family:monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace">    // Grab a highly sensitive object</span></div><div style="margin-left:40px"><span style="font-family:monospace">    final NuclearLaunchButton btn = NuclearLaunchButton.instance();</span></div><div style="margin-left:40px"><span style="font-family:monospace">    ...</span></div><div style="margin-left:40px"><span style="font-family:monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace">    // Do other stuff...</span></div><div style="margin-left:40px"><span style="font-family:monospace">    ...</span></div><div style="margin-left:40px"><span style="font-family:monospace">}</span></div><div><br></div><div>It would be nice to know as soon as possible when "btn" is no longer going to be used in that method.</div><div><br></div><div>So this is a perfectly appropriate task for IDE's or static code checkers, e.g.:</div><div><br></div><div><div style="margin-left:40px"><span style="font-family:monospace">void method() {</span></div><div style="margin-left:40px"><span style="font-family:monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace">    // Grab a highly sensitive object</span></div><div style="margin-left:40px"><span style="font-family:monospace">    final NuclearLaunchButton btn = NuclearLaunchButton.instance();</span></div><div style="margin-left:40px"><span style="font-family:monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace">    // Check status</span></div><div style="margin-left:40px"><span style="font-family:monospace">    final boolean armed = btn.isArmed();    // <b>@last-use(btn)</b></span></div><div style="margin-left:40px"><span style="font-family:monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace">    // Do other stuff...</span></div><div style="margin-left:40px"><span style="font-family:monospace">}</span></div></div><div><br></div><div>-Archie</div></div>
</blockquote></div></div>