8f0885ca03
To better emphasize the fact that all returned properties require an instance of the class they are declared in. Another issue was that 'Some::class.extensionProperties' was sometimes incorrectly perceived as "get all extension properties available on the class Some"
21 lines
640 B
Kotlin
Vendored
21 lines
640 B
Kotlin
Vendored
import kotlin.reflect.jvm.kotlin
|
|
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)
|
|
}
|