New candidate JEP: 443: Unnamed Patterns and Variables (Preview)
Holo The Sage Wolf
holo3146 at gmail.com
Tue Mar 21 21:39:50 UTC 2023
Is there a reason not to allow implicit Unnamed Variables in
try-with-resources and Catch-block?
To allow:
try (Scope.open()) {
...
}
---
try { ... }
catch (Exception) { ... }
to be implicitly
try (var _ = Scope.open()) {
...
}
---
try { ... }
catch (Exception _) { ... }
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.
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.
This implicitness will make stuff like logging context, which is far from a
niche use case, much more elegant.
On Tue, Mar 21, 2023 at 9:17 PM Mark Reinhold <mark.reinhold at oracle.com>
wrote:
> https://openjdk.org/jeps/443
>
> Summary: Enhance the Java language with unnamed patterns, which match
> a record component without stating the component's name or type,
> and unnamed variables, which can be initialized but not used. Both
> are denoted by an underscore character, _. This is a preview language
> feature.
>
> - Mark
--
Holo The Wise Wolf Of Yoitsu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230321/cd4025d1/attachment.htm>
More information about the amber-dev
mailing list