set Value
Для Kotlin: 1.4
inline operator fun <V> KMutableProperty0<V>.setValue(thisRef: Any?, property: KProperty<*>, value: V)
Оператор-расширение, позволяющий делегировать изменяемое свойство типа V ссылке на изменяемое свойство того же типа V.
Получатель
Ссылка на изменяемое свойство типа V. Ссылка не имеет получателя, то есть она ссылается либо на свойство верхнего уровня, либо на свойство с привязанным к нему получателем.
Пример:
class Login(val username: String, var incorrectAttemptCounter: Int = 0)
val defaultLogin = Login("Admin")
var defaultLoginAttempts by defaultLogin::incorrectAttemptCounter
// equivalent to
var defaultLoginAttempts: Int
get() = defaultLogin.incorrectAttemptCounter
set(value) { defaultLogin.incorrectAttemptCounter = value }
inline operator fun <T, V> KMutableProperty1<T, V>.setValue(thisRef: T, property: KProperty<*>, value: V)
Оператор-расширение, позволяющий делегировать изменяемое свойство-член или свойство-расширение типа V ссылке на изменяемое свойство-член или свойство-расширение того же типа V.
Получатель
Ссылка на свойство типа V или его подтипа, доступное только для чтения или изменяемое. Ссылка имеет непривязанный получатель типа T.
Пример:
class Login(val username: String, var incorrectAttemptCounter: Int)
var Login.attempts by Login::incorrectAttemptCounter
// equivalent to
var Login.attempts: Int
get() = this.incorrectAttemptCounter
set(value) { this.incorrectAttemptCounter = value }
© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/set-value.html