mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-09 15:53:37 +00:00
The former name clashes with java.lang.IllegalAccessException and proved to be inconvenient because it should always be qualified in the source. Also use java.lang exception's message as kotlin.reflect exception's message
30 lines
670 B
Kotlin
30 lines
670 B
Kotlin
import kotlin.reflect.IllegalPropertyAccessException
|
|
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: IllegalPropertyAccessException) { }
|
|
|
|
p.accessible = true
|
|
|
|
val r = p.get(Result())
|
|
|
|
p.accessible = false
|
|
try {
|
|
p.get(Result())
|
|
return "Fail: setAccessible(false) had no effect"
|
|
} catch(e: IllegalPropertyAccessException) { }
|
|
|
|
return r
|
|
}
|