Skip to content

Commit

Permalink
add a delegate example
Browse files Browse the repository at this point in the history
  • Loading branch information
REBOOTERS committed Nov 16, 2024
1 parent d17dd0b commit 913f944
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.engineer.compose.uitls

import kotlin.reflect.KProperty

class Delegate {
operator fun getValue(thisRef: Any?, property: KProperty<*>): String {
return "$thisRef, thank you for delegating '${property.name}' to me!"
}
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) {
println("$value has been assigned to '${property.name}' in $thisRef.")
}
}

fun main() {
var p by Delegate()
println(p)
p = "hello"
println(p)
}

0 comments on commit 913f944

Please sign in to comment.