Files
kotlin/compiler/testData/codegen/boxWithStdlib/reflection/properties/getPropertiesMutableVsReadonly.kt
Alexander Udalov 8d9618348d Move .java and .kotlin extension properties to kotlin.jvm
Delete the old ones in package kotlin.reflect.jvm because otherwise the code
using those functions will become red in a lot less meaningful way (overload
resolution ambiguity) than if they're deleted (unresolved import)

Based on the work originally done by @dnpetrov

 #KT-8380 Fixed
2015-08-27 08:19:50 +03:00

20 lines
607 B
Kotlin
Vendored

import kotlin.reflect.*
class A(val readonly: String) {
var mutable: String = "before"
}
fun box(): String {
val props = javaClass<A>().kotlin.memberProperties
val readonly = props.single { it.name == "readonly" }
assert(readonly !is KMutableProperty1<A, *>) { "Fail 1: $readonly" }
val mutable = props.single { it.name == "mutable" }
assert(mutable is KMutableProperty1<A, *>) { "Fail 2: $mutable" }
val a = A("")
mutable as KMutableProperty1<A, String>
assert(mutable[a] == "before") { "Fail 3: ${mutable.get(a)}" }
mutable[a] = "OK"
return mutable.get(a)
}