<div dir="auto">Indeed, the emphasis I tried to make was about making it *implicit* unnamed</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 22, 2023, 14:37 Red IO <<a href="mailto:redio.development@gmail.com">redio.development@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">I think he suggests to get rid of the variable entirely like in his example:<div dir="auto"><br></div><div dir="auto">try {</div><div dir="auto"><br></div><div dir="auto">} catch (Exception) //<- nothing here</div><div dir="auto">{</div><div dir="auto">} </div><div dir="auto"><br></div><div dir="auto">And try (new AutoclosableImpl()) {//<- no assignment to a variable </div><div dir="auto"><br></div><div dir="auto">} </div><div dir="auto"><br></div><div dir="auto">Great regards </div><div dir="auto">RedIODev </div><br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Wed, Mar 22, 2023, 13:19 Brian Goetz <<a href="mailto:brian.goetz@oracle.com" target="_blank" rel="noreferrer">brian.goetz@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<br>
<br>
<div>On 3/21/2023 5:39 PM, Holo The Sage
Wolf wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>
<p style="margin:0px 0px 1.2em!important">Is there a reason
not to allow implicit Unnamed Variables in
try-with-resources and Catch-block?</p>
</div>
</div>
</blockquote>
<br>
The JEP already describes these cases:<br>
<br>
<h3 id="m_-5153980427867079586m_6978129878642980364Unnamed-variables" style="font-size:10pt;font-weight:bold;font-style:italic;padding:0pt;margin:1ex 0pt;color:rgb(0,0,0);font-family:"DejaVu Sans","Bitstream Vera Sans","Luxi Sans",Verdana,Arial,Helvetica;font-variant-ligatures:normal;font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial">Unnamed variables</h3>
<p>The following kinds of
declarations can introduce either a named variable (denoted by an
identifier) or an unnamed variable (denoted by an underscore):</p>
<ul>
<li style="margin-top:0pt;margin-bottom:0pt">A local variable
declaration statement in a block (JLS 14.4.2),</li>
<li style="margin-top:0pt;margin-bottom:0pt">A resource
specification of a<span> </span><code>try</code>-with-resources statement (JLS 14.20.3),</li>
<li style="margin-top:0pt;margin-bottom:0pt">The header of a
basic<span> </span><code>for</code><span> </span>statement
(JLS 14.14.1),</li>
<li style="margin-top:0pt;margin-bottom:0pt">The header of an
enhanced<span> </span><code>for</code><span> </span>loop
(JLS 14.14.2),</li>
<li style="margin-top:0pt;margin-bottom:0pt">An exception
parameter of a<span> </span><code>catch</code><span> </span>block (JLS 14.20), and</li>
<li style="margin-top:0pt;margin-bottom:0pt">A formal
parameter of a lambda expression (JLS 15.27.1).</li>
</ul>
<br>
Try with resources, and catch blocks, are listed as places where you
can use unnamed variables. Am I undersatnding your question
properly?<br>
<br>
<br>
<br>
<blockquote type="cite">
<div dir="ltr">
<div>
<p style="margin:0px 0px 1.2em!important">To allow:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)"> <span style="color:rgb(51,51,51);font-weight:bold">try</span> (Scope.open()) {
...
}
---
<span style="color:rgb(51,51,51);font-weight:bold">try</span> { ... }
<span style="color:rgb(51,51,51);font-weight:bold">catch</span> (Exception) { ... }
</code></pre>
<p style="margin:0px 0px 1.2em!important">to be implicitly</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)"> <span style="color:rgb(51,51,51);font-weight:bold">try</span> (var _ = Scope.open()) {
...
}
---
<span style="color:rgb(51,51,51);font-weight:bold">try</span> { ... }
<span style="color:rgb(51,51,51);font-weight:bold">catch</span> (Exception _) { ... }
</code></pre>
<p style="margin:0px 0px 1.2em!important">Unlike a normal
expression, and expression on the RHS of a
try-with-resources variable has an explicit context, there
is no fear of someone forgetting the result of the
expression by mistake.</p>
<p style="margin:0px 0px 1.2em!important">In a Catch block the
exception is uniquely accessible through the variable
declared in the declaration of the block, so there is no
fear that someone will get confused by this implicitness.</p>
<p style="margin:0px 0px 1.2em!important">This implicitness
will make stuff like logging context, which is far from a
niche use case, much more elegant.</p>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, Mar 21, 2023 at
9:17 PM Mark Reinhold <<a href="mailto:mark.reinhold@oracle.com" rel="noreferrer noreferrer" target="_blank">mark.reinhold@oracle.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"><a href="https://openjdk.org/jeps/443" rel="noreferrer noreferrer noreferrer" target="_blank">https://openjdk.org/jeps/443</a><br>
<br>
Summary: Enhance the Java language with unnamed patterns,
which match<br>
a record component without stating the component's name or
type,<br>
and unnamed variables, which can be initialized but not
used. Both<br>
are denoted by an underscore character, _. This is a preview
language<br>
feature.<br>
<br>
- Mark</blockquote>
</div>
<br clear="all">
<div><br>
</div>
<span>-- </span><br>
<div dir="ltr">
<div dir="ltr">Holo The Wise Wolf Of Yoitsu</div>
</div>
</blockquote>
<br>
</div>
</blockquote></div></div>
</blockquote></div>