b68e47f705
Move 'volatile' and 'synchronized' to package 'kotlin' in stdlib. Also delete 'atomic', since its support was never implemented
27 lines
586 B
Kotlin
27 lines
586 B
Kotlin
public open class TestDelegate<T: Any>(private val initializer: () -> T) {
|
|
private var value: T? = null
|
|
|
|
public open fun get(thisRef: Any?, desc: PropertyMetadata): T {
|
|
if (value == null) {
|
|
value = initializer()
|
|
}
|
|
return value!!
|
|
}
|
|
|
|
public open fun set(thisRef: Any?, desc: PropertyMetadata, svalue : T) {
|
|
value = svalue
|
|
}
|
|
}
|
|
|
|
class A {}
|
|
class B {}
|
|
|
|
public val A.s: String by TestDelegate( {"OK2"})
|
|
public val B.s: String by TestDelegate( {"OK"})
|
|
|
|
fun box() : String {
|
|
if (A().s != "OK2") return "fail1"
|
|
|
|
return B().s
|
|
}
|