Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumKotlinclass delegation bySingle-choice MCQ

When a custom delegate provider declares `provideDelegate`, when does that function run for a member property?

import kotlin.reflect.KProperty class Trace { operator fun provideDelegate(t: Any?, p: KProperty<*>): Trace { println("provide ${p.name}") return this } operator fun getValue(t: Any?, p: KProperty<*>) = 42 } class Host { val x: Int by Trace() } fun main() { print("before; ") val h = Host() print("after; ") println(h.x) }