setValue

Function

Common
public inline operator fun MutableDoubleState.setValue(
    thisObj: Any?,
    property: KProperty<*>,
    value: Double,
)

Permits property delegation of vars using by for MutableDoubleState.

Common
public inline operator fun MutableFloatState.setValue(
    thisObj: Any?,
    property: KProperty<*>,
    value: Float,
)

Permits property delegation of vars using by for MutableFloatState.

Common
public inline operator fun <T> MutableState<T>.setValue(
    thisObj: Any?,
    property: KProperty<*>,
    value: T,
)

Permits property delegation of vars using by for MutableState.

Common
public inline operator fun MutableIntState.setValue(
    thisObj: Any?,
    property: KProperty<*>,
    value: Int,
)

Permits property delegation of vars using by for MutableIntState.

Common
public inline operator fun MutableLongState.setValue(
    thisObj: Any?,
    property: KProperty<*>,
    value: Long,
)

Permits property delegation of vars using by for MutableLongState.

Code Examples

DelegatedStateSample

// TODO: operator assignment for local delegated properties is currently not supported
// https://github.com/JetBrains/kotlin/blob/11f3c4b03f40460160c1f23b634941a867fd817b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java#L2268
@Suppress("ReplaceWithOperatorAssignment")
@Composable
fun DelegatedStateSample() {
    var count by remember { mutableStateOf(0) }
    Text(text = "You clicked $count times")
    Button(onClick = { count = count + 1 }) { Text("Click me") }
}