Home » openjdk-7 » java » lang » [javadoc | source]
public interface: AutoCloseable [javadoc | source] A resource that must be closed when it is no longer needed.
Method from java.lang.AutoCloseable Summary:
Method from java.lang.AutoCloseable Detail:
 public  void close() throws Exception
    Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the {@code try}-with-resources statement.

    While this interface method is declared to throw {@code Exception}, implementers are strongly encouraged to declare concrete implementations of the {@code close} method to throw more specific exceptions, or to throw no exception at all if the close operation cannot fail.

    Implementers of this interface are also strongly advised to not have the {@code close} method throw InterruptedException . This exception interacts with a thread's interrupted status, and runtime misbehavior is likely to occur if an {@code InterruptedException} is {@linkplain Throwable#addSuppressed suppressed}. More generally, if it would cause problems for an exception to be suppressed, the {@code AutoCloseable.close} method should not throw it.

    Note that unlike the close method of java.io.Closeable , this {@code close} method is not required to be idempotent. In other words, calling this {@code close} method more than once may have some visible side effect, unlike {@code Closeable.close} which is required to have no effect if called more than once. However, implementers of this interface are strongly encouraged to make their {@code close} methods idempotent.