Files
kotlin-fork/compiler/testData/codegen/boxWithStdlib/reflection/properties/protectedClassVar.kt
T
Alexander Udalov 50dbda1e1a Introduce KClass.members, make properties/extensionProperties extensions
To avoid significant growth of KClass and KPackage interfaces
2015-07-29 21:36:36 +03:00

30 lines
681 B
Kotlin
Vendored

import kotlin.reflect.*
import kotlin.reflect.jvm.accessible
class A(param: String) {
protected var v: String = param
fun ref() = A::class.properties.single() as KMutableProperty1<A, String>
}
fun box(): String {
val a = A(":(")
val f = a.ref()
try {
f.get(a)
return "Fail: protected property getter is accessible by default"
} catch (e: IllegalPropertyAccessException) { }
try {
f.set(a, ":D")
return "Fail: protected property setter is accessible by default"
} catch (e: IllegalPropertyAccessException) { }
f.accessible = true
f.set(a, ":)")
return if (f[a] != ":)") "Fail: ${f[a]}" else "OK"
}