Revisiting MayHoldCloseableResource
Doug Lea
dl at cs.oswego.edu
Tue Aug 20 03:40:27 PDT 2013
On 08/19/2013 08:43 PM, Joe Bowbeer wrote:
> Agree.
>
> Though [need not do so] seems awkward below:
>
Thanks. Take two:
/**
* An object that may hold resources (such as file or socket handles)
* until it is closed. The {@link #close()} method of an AutoCloseable
* object is called automatically when exiting a {@code
* try}-with-resources block for which the object has been declared in
* the header. This construction ensures prompt release, avoiding
* resource exhaustion exceptions and errors that may otherwise occur.
*
* @apiNote
* <p>It is possible, and in fact common, for a base class to
* implement AutoCloseable even though not all of its subclasses or
* instances hold releasable resources. It is best practice for usages
* applying to <em>any</em> possible subclass to use {@code
* try}-with-resources constructions. However, in frameworks such as
* {@link java.util.Stream} that support both IO-based and
* non-IO-based forms, {@code try}-with-resources blocks are in
* general unnecessary when using non-IO-based forms.
*
* @author Josh Bloch
* @since 1.7
*/
@FunctionalInterface
public interface AutoCloseable {
More information about the lambda-libs-spec-observers
mailing list