jdk/src/share/classes/java/lang/AutoCloseable.java
changeset 19798 b627a06c30ed
parent 15647 314007859004
child 21307 d9d1ad598db1
equal deleted inserted replaced
19797:97e6c52edd16 19798:b627a06c30ed
    24  */
    24  */
    25 
    25 
    26 package java.lang;
    26 package java.lang;
    27 
    27 
    28 /**
    28 /**
    29  * A resource that must be closed when it is no longer needed.
    29  * An object that may hold resources (such as file or socket handles)
       
    30  * until it is closed. The {@link #close()} method of an {@code AutoCloseable}
       
    31  * object is called automatically when exiting a {@code
       
    32  * try}-with-resources block for which the object has been declared in
       
    33  * the resource specification header. This construction ensures prompt
       
    34  * release, avoiding resource exhaustion exceptions and errors that
       
    35  * may otherwise occur.
       
    36  *
       
    37  * @apiNote
       
    38  * <p>It is possible, and in fact common, for a base class to
       
    39  * implement AutoCloseable even though not all of its subclasses or
       
    40  * instances will hold releasable resources.  For code that must operate
       
    41  * in complete generality, or when it is known that the {@code AutoCloseable}
       
    42  * instance requires resource release, it is recommended to use {@code
       
    43  * try}-with-resources constructions. However, when using facilities such as
       
    44  * {@link java.util.stream.Stream} that support both I/O-based and
       
    45  * non-I/O-based forms, {@code try}-with-resources blocks are in
       
    46  * general unnecessary when using non-I/O-based forms.
    30  *
    47  *
    31  * @author Josh Bloch
    48  * @author Josh Bloch
    32  * @since 1.7
    49  * @since 1.7
    33  */
    50  */
    34 @FunctionalInterface
    51 @FunctionalInterface