Files
kotlin-fork/compiler/testData/codegen/boxWithStdlib/reflection/properties/privateClassVar.kt
T
Alexander Udalov 8f0885ca03 Rename KClass.properties and extensionProperties: prepend 'member'
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"
2015-07-29 21:36:47 +03:00

31 lines
623 B
Kotlin
Vendored

import kotlin.reflect.*
import kotlin.reflect.jvm.accessible
class A {
private var value = 0
fun ref() = A::class.memberProperties.single() as KMutableProperty1<A, Int>
}
fun box(): String {
val a = A()
val p = a.ref()
try {
p.set(a, 1)
return "Fail: private property is accessible by default"
} catch(e: IllegalPropertyAccessException) { }
p.accessible = true
p.set(a, 2)
p.get(a)
p.accessible = false
try {
p.set(a, 3)
return "Fail: setAccessible(false) had no effect"
} catch(e: IllegalPropertyAccessException) { }
return "OK"
}