a38a396a43
Basic reflection is usable without any imports (with :: literals)
This reverts commit 9503056dd5.
29 lines
601 B
Kotlin
29 lines
601 B
Kotlin
import kotlin.reflect.KMemberProperty
|
|
import kotlin.reflect.jvm.accessible
|
|
|
|
class Result {
|
|
private val value = "OK"
|
|
|
|
fun ref(): KMemberProperty<Result, String> = ::value
|
|
}
|
|
|
|
fun box(): String {
|
|
val p = Result().ref()
|
|
try {
|
|
p.get(Result())
|
|
return "Fail: private property is accessible by default"
|
|
} catch(e: IllegalAccessException) { }
|
|
|
|
p.accessible = true
|
|
|
|
val r = p.get(Result())
|
|
|
|
p.accessible = false
|
|
try {
|
|
p.get(Result())
|
|
return "Fail: setAccessible(false) had no effect"
|
|
} catch(e: IllegalAccessException) { }
|
|
|
|
return r
|
|
}
|