Skip to content

Commit 913f944

Browse files
committed
add a delegate example
1 parent d17dd0b commit 913f944

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.engineer.compose.uitls
2+
3+
import kotlin.reflect.KProperty
4+
5+
class Delegate {
6+
operator fun getValue(thisRef: Any?, property: KProperty<*>): String {
7+
return "$thisRef, thank you for delegating '${property.name}' to me!"
8+
}
9+
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) {
10+
println("$value has been assigned to '${property.name}' in $thisRef.")
11+
}
12+
}
13+
14+
fun main() {
15+
var p by Delegate()
16+
println(p)
17+
p = "hello"
18+
println(p)
19+
}

0 commit comments

Comments
 (0)