Added tests.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
fun foo(): Int {
|
||||
class Delegate {
|
||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||
println(p.name)
|
||||
return 42
|
||||
}
|
||||
}
|
||||
|
||||
val x: Int by Delegate()
|
||||
|
||||
return x
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println(foo())
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Delegate {
|
||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||
println(p.name)
|
||||
return 42
|
||||
}
|
||||
}
|
||||
|
||||
val x: Int by Delegate()
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println(x)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Delegate {
|
||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||
println(p.name)
|
||||
return 42
|
||||
}
|
||||
}
|
||||
|
||||
class C {
|
||||
val x: Int by Delegate()
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println(C().x)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Delegate {
|
||||
var f: Int = 42
|
||||
|
||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||
println("get ${p.name}")
|
||||
return f
|
||||
}
|
||||
|
||||
operator fun setValue(receiver: Any?, p: KProperty<*>, value: Int) {
|
||||
println("set ${p.name}")
|
||||
f = value
|
||||
}
|
||||
}
|
||||
|
||||
class C {
|
||||
var x: Int by Delegate()
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val c = C()
|
||||
println(c.x)
|
||||
c.x = 117
|
||||
println(c.x)
|
||||
}
|
||||
Reference in New Issue
Block a user