mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-12 08:31:28 +00:00
25 lines
537 B
Kotlin
Vendored
25 lines
537 B
Kotlin
Vendored
import kotlin.reflect.KProperty
|
|
|
|
var result: String by Delegate
|
|
|
|
object Delegate {
|
|
var value = "lol"
|
|
|
|
operator fun getValue(instance: Any?, data: KProperty<*>): String {
|
|
return value
|
|
}
|
|
|
|
operator fun setValue(instance: Any?, data: KProperty<*>, newValue: String) {
|
|
value = newValue
|
|
}
|
|
}
|
|
|
|
fun box(): String {
|
|
val f = ::result
|
|
if (f.get() != "lol") return "Fail 1: {$f.get()}"
|
|
Delegate.value = "rofl"
|
|
if (f.get() != "rofl") return "Fail 2: {$f.get()}"
|
|
f.set("OK")
|
|
return f.get()
|
|
}
|