Proposal: Automatic Resource Management

Vilya Harvey vilya.harvey at gmail.com
Mon Mar 9 12:52:00 PDT 2009


2009/3/9 Reinier Zwitserloot <reinier at zwitserloot.com>

> Vilya, you can check the entire history of this mailing list over at:
>
> http://mail.openjdk.java.net/pipermail/coin-dev/
>
> Afaik, the latest version of the ARM proposal is here. Assuming Josh
> turned auto-republish on, this URL should always point at the latest
> version:
>
> http://docs.google.com/Doc?id=ddv8ts74_0vnstdfdh
>
> AutoClosable idea sounds good to me too, FWIW.
>

Thanks a lot Reiner, I've just read the proposal.

The only thing in it I wasn't too sure about was having variable
declarations inside the parentheses. It works well in the examples given,
but I can think of a few cases where it gets a bit ugly:

   - using an anonymous class as an adapter to implement AutoCloseable when
   an existing class doesn't implement it;
   - using with a resource managing class which requires you to call a void
   connect() method or similar to actually get the resource, instead of
   grabbing it in the constructor.

Both of these would be slightly better if expressions (i.e. references to
existing variables) were allowed inside the parentheses. You can work around
this under the existing proposal:

AutoCloseable ac = ... ;
try (AutoCloseable acRef = ac) { ... }

but that seems (to me) to obscure the fact that ac will be closed afterwards
even more than if ac was listed on it's own inside the parentheses.

Apologies if any of the above is unclear, or if this has already been
discussed - I'm still going through the earlier posts in the archive.

Vil.



More information about the coin-dev mailing list