Box

data class Box<T : Any>(generator: () -> T, 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)

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.