getValue

inline operator fun <V> KProperty0<V>.getValue(thisRef: Any?, property: KProperty<*>): V(source)

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.

Since Kotlin

1.4

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

inline operator fun <T, V> KProperty1<T, V>.getValue(thisRef: T, property: KProperty<*>): V(source)

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.

Since Kotlin

1.4

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

inline operator fun <T> Lazy<T>.getValue(thisRef: Any?, property: KProperty<*>): T(source)

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 }

Since Kotlin

1.0

Samples

import samples.assertPrints
import kotlin.concurrent.thread

fun main() { 
   //sampleStart 
   val answer: Int by lazy {
    println("Computing the answer to the Ultimate Question of Life, the Universe, and Everything")
    42
}

println("What is the answer?")
// Will print 'Computing...' and then 42
println(answer) // 42
println("Come again?")
// Will just print 42
println(answer) // 42 
   //sampleEnd
}