Files
kotlin-fork/compiler/testData/codegen/boxWithStdlib/reflection/properties/callPrivatePropertyFromGetProperties.kt
T
Alexander Udalov 30794060a9 Simplify property hierarchy in reflection
Leave only 3*2 = 6 classes: KProperty0, KProperty1, KProperty2 and their
mutable analogs, depending on the number of receivers a property takes
2015-07-10 20:10:09 +03:00

20 lines
413 B
Kotlin
Vendored

import kotlin.reflect.*
import kotlin.reflect.jvm.*
class K(private val value: String)
fun box(): String {
val p = javaClass<K>().kotlin.properties.single() as KProperty1<K, String>
try {
return p.get(K("Fail: private property should not be accessible by default"))
}
catch (e: IllegalPropertyAccessException) {
// OK
}
p.accessible = true
return p.get(K("OK"))
}