Fwd: Draft JEP: Unnamed local variables and patterns
Brian Goetz
brian.goetz at oracle.com
Wed Oct 19 15:04:09 UTC 2022
Received on the -comments list, on the subject of unnamed locals in TWR.
-------- Forwarded Message --------
Subject: Re: Draft JEP: Unnamed local variables and patterns
Date: Tue, 18 Oct 2022 06:43:18 +0000
From: Till Brychcy <till.brychcy at unite.eu>
To: amber-spec-comments at openjdk.org <amber-spec-comments at openjdk.org>
> 7. a resource specification of a try-with-resources statement
>
> Today we get this warning with a TWR-statement if the local is ignored:
>
> >
> javac -Xlint:all MyScopedLock.java
>
> MyScopedLock.java:23: warning: [try] auto-closeable resource ignored
is never referenced in body of corresponding try statement
> try(MyScopedLock ignored = l.lock()) {
> ^
> 1 warning
>
> So here we may have a clash of philosophies for the enhanced-for and
how people
> use the `AutoCloseable`.
We have a similar use case: a logging framework that uses the close()
call to measure the runtime of some code block.
It looks like this:
try (__ __ = ThreadLogger.block(SomeClass.class, "someAction")) {
// some code
}
Note we named the helper class and variable already "__" to make clear
that they are not used - before Java 8 we used to called them "_“ :-)
Big advantages in comparison to e.g. a lambda based solution are that
this doesn’t interfere with exceptions and variables outside the try
statement can be assigned.
There are also more cases reported by other people in
https://bugs.eclipse.org/bugs/show_bug.cgi?id=560733 , which why an
already implemented warning for such variables by Eclipse was removed again.
Wir stellen uns als Marke neu auf und stehen mehr denn je zusammen.
Unite ist nun unsere führende Unternehmensmarke.
*Erfahren Sie mehr* <https://we.unite.eu/de/>
Folgen Sie uns auf *LinkedIn*
<https://www.linkedin.com/company/unite-network>, *Twitter*
<https://twitter.com/weunite_global> oder *YouTube*
<https://www.youtube.com/c/uniteglobal>
*unite.eu* <http://unite.eu/>
Unite Services GmbH & Co. KG, im Auftrag von Unite
Unite Network SE
Neumarkt 9, 04109 Leipzig, Deutschland | Amtsgericht Leipzig, HRB 39278
Vorstand: Dr. Sebastian Wieser (Vorsitzender), Christel Constant, Peter Ledermann, Dr. Bernd Schönwälder
Aufsichtsrat: Karl Mayer‑Rieckh (Vorsitzender)
Mercateo Deutschland AG
Mercateo Deutschland AG Fürstenfelder Straße 5, 80331 München, Deutschland | Amtsgericht München, HRB 243681
Vorstand: Dr. Sebastian Wieser (Vorsitzender), Christel Constant, Peter Ledermann, Dr. Bernd Schönwälder
Aufsichtsrat: Karl Mayer‑Rieckh (Vorsitzender)
*mercateo.com/procure* <https://www.mercateo.com/procure/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-observers/attachments/20221019/90b46a93/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image985586.png
Type: image/png
Size: 4303 bytes
Desc: not available
URL: <https://mail.openjdk.org/pipermail/amber-spec-observers/attachments/20221019/90b46a93/image985586-0001.png>
More information about the amber-spec-observers
mailing list