Mutable

class Mutable<T>(var value: T)

Support explicit mutable wrapping of variables. This was useful when the VM was in Java, since values captured by inner classes and lambdas could only be immutable. Kotlin introduces its own mutable wrappers for captured vars, but this is still occasionally useful.

Author

Mark van Gulik

Parameters

T

The type of mutable object.

value

The initial value.

Constructors

Link copied to clipboard
fun <T> Mutable(value: T)

Constructor that takes an initial value.

Functions

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
inline fun update(updater: T.() -> T)

Update the Mutable via an extension function. Within the function, the receiver will be the old value of the Mutable, and the function must return a replacement value.

Properties

Link copied to clipboard
var value: T

Expose a public field for readability.