java.lang · java.base · since Java 1.7

AutoCloseable

declaration
public interface AutoCloseable

The try-with-resources contract: anything with a close() method can be managed declaratively, with suppressed-exception bookkeeping for free.

  • Implement it on every resource-owning class you write (EJ 9)

Key methods

void close() throws ExceptionRelease the resource; called automatically in reverse declaration order.