getValue

Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)
operator fun <V> KProperty0<V>.getValue(
    thisRef: Any?, 
    property: KProperty<*>
): V

An extension operator that allows delegating a read-only property of type V to a property reference to a property of type V or its subtype.

Receiver

A property reference to a read-only or mutable property of type V or its subtype. The reference is without a receiver, i.e. it either references a top-level property or has the receiver bound to it.

Example:

class Login(val username: String)
val defaultLogin = Login("Admin")
val defaultUsername by defaultLogin::username
// equivalent to
val defaultUserName get() = defaultLogin.username
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)
operator fun <T, V> KProperty1<T, V>.getValue(
    thisRef: T, 
    property: KProperty<*>
): V

An extension operator that allows delegating a read-only member or extension property of type V to a property reference to a member or extension property of type V or its subtype.

Receiver

A property reference to a read-only or mutable property of type V or its subtype. The reference has an unbound receiver of type T.

Example:

class Login(val username: String)
val Login.user by Login::username
// equivalent to
val Login.user get() = this.username
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
operator fun <T> Lazy<T>.getValue(
    thisRef: Any?, 
    property: KProperty<*>
): T

An extension to delegate a read-only property of type T to an instance of Lazy.

This extension allows to use instances of Lazy for property delegation: val property: String by lazy { initializer }

© 2010–2021 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/get-value.html