com.seeq.utilities.lang.AutoCloseables.kt Maven / Gradle / Ivy
The newest version!
package com.seeq.utilities.lang
import java.io.Closeable
/**
* An [AutoCloseable] which declares no checked exceptions.
* This interface is useful for defining ad-hoc try-with-resources interfaces via lambda-converted return values.
*
* ### Example:
*
* ```java
* RuntimeAutoCloseable withResource(Resource r) {
* r.start();
* return r::end;
* }
* ```
*/
fun interface RuntimeAutoCloseable : AutoCloseable {
/**
* Closes the resource without throwing checked exceptions.
* Unlike [Closeable], this is not required to be idempotent.
*
* @see AutoCloseable.close
* @see RuntimeCloseable
*/
override fun close()
}
/**
* A [Closeable] which declares no checked exceptions.
* This interface is useful for defining ad-hoc try-with-resources interfaces via lambda-converted return values.
*
* ### Example:
*
* ```java
* RuntimeCloseable withResource(Resource r) {
* r.start();
* return r::end;
* }
* ```
*/
fun interface RuntimeCloseable : RuntimeAutoCloseable, Closeable {
/**
* Closes the resource without throwing checked exceptions.
* Per the requirement of [Closeable.close], the implementation must be idempotent.
*
* @see Closeable.close
* @see RuntimeAutoCloseable
*/
override fun close()
}