Some Classes with a public void close() don't implement AutoCloseable
John Rose
john.r.rose at oracle.com
Thu Apr 16 21:31:49 UTC 2020
Nice. I tried to find a way to make this a little more generic
and came up with an API which handles arbitrary exceptions
and is packaged as a method instead of a special idiom.
There’s a natural-enough method called `forceTryable` that
could be created.
http://cr.openjdk.java.net/~jrose/jdk/ForceTryableDemo.java
https://bugs.openjdk.java.net/browse/JDK-8243015
(There are further generalizations of this, if you look at it as
a “named cast method” for a functional interface type related
to AutoCloseable. See my comment on JDK-8243015.)
— John
On Apr 15, 2020, at 8:53 AM, Remi Forax <forax at univ-mlv.fr> wrote:
>
> interface FakeAutoCloseable extends AutoCloseable { public void close(); } // suppress exception
>
> XMLReader xmlReader = ...
> try(FakeAutoCloseable __ = xmlReader::close) {
> …
>
More information about the discuss
mailing list