Box

data class Box<T : Any>(val generator: () -> T, var value: T? = null)(source)

A lazily-instantiated reference to an object of type T.

Parameters

T

the type of the referenced object

generator

generates the referenced object when unaryPlus is invoked for the first time

value

do not assign this field in the constructor; this field is placed in the constructor to ensure Kotlin includes it in the automatically-generated copy method

Constructors

Link copied to clipboard
constructor(generator: () -> T, value: T? = null)

Properties

Link copied to clipboard
private val generator: () -> T
Link copied to clipboard
private var value: T?

Functions

Link copied to clipboard
operator fun unaryPlus(): T

If this method is invoked for the first time, generator is invoked and the result is returned. In subsequent invocations of this method, the previously-generated value is returned each time.