Closeable

@API(status = API.Status.STABLE, since = "2.7.1")
abstract class Closeable<T : Any> : PropertyDelegateProvider<Nothing, T>

An atomic reference value, which has methods that define its creation and disposal / being closed. This class should be used as an anonymous object such as:

val closeable = object : Closeable<Type>() {
override fun create(): T {
// create and return T
}

override fun onClose() {
// dispose of T
}

Parameters

T

The type of the value.

Constructors

Link copied to clipboard
fun Closeable()

Functions

Link copied to clipboard
fun close(): T?

Sets value to false and closed to true. If overridden, should set closed to true and call onClose if used.

Link copied to clipboard
abstract fun create(): T

Create a new instance of the value or just update it then return itself if needed.

Link copied to clipboard
fun get(): T
Link copied to clipboard
operator fun getValue(ref: Any, property: KProperty<*>): T
Link copied to clipboard
open fun onClose()

Called when close is called but before the value is disposed of.

Link copied to clipboard
operator override fun provideDelegate(thisRef: Nothing, property: KProperty<*>): T