mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-05 07:30:09 +08:00
Create delegate test
This commit is contained in:
parent
576ade8cc5
commit
72d9541070
26
mirai-debug/src/main/kotlin/test/DelegateTest.kt
Normal file
26
mirai-debug/src/main/kotlin/test/DelegateTest.kt
Normal file
@ -0,0 +1,26 @@
|
||||
package test
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
|
||||
data class Info(
|
||||
var value: Int
|
||||
) {
|
||||
operator fun getValue(c: C, property: KProperty<*>): Int {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
class C(var info: Info) {
|
||||
val value by info
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val info = Info(1)
|
||||
val c = C(info)
|
||||
println(c.value) //1
|
||||
info.value = 2
|
||||
println(c.value) //2
|
||||
c.info = Info(3)
|
||||
println(c.value) //2
|
||||
}
|
Loading…
Reference in New Issue
Block a user