Added in API level 19

AutoCloseable

interface AutoCloseable
java.lang.AutoCloseable

An object that may hold resources (such as file or socket handles) until it is closed. The close() method of an AutoCloseable object is called automatically when exiting a try-with-resources block for which the object has been declared in the resource specification header. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur.

Summary

Public methods
abstract Unit

Closes this resource, relinquishing any underlying resources.

Public methods

close

Added in API level 19
abstract fun close(): Unit

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

Exceptions
java.lang.Exception if this resource cannot be closed