singleSetReference

fun <T> singleSetReference(initValue: T? = null, compareValue: T? = null): ReadWriteProperty<Any?, T?>

Creates a thread-safe delegate that can only be set once via compare-and-set.

Attempting to set the property a second time throws IllegalStateException.

Return

a ReadWriteProperty delegate

Parameters

initValue

optional initial value (default null)

compareValue

the expected value for the compare-and-set operation (default null)

Type Parameters

T

the property type