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
653 B
Kotlin
30 lines
653 B
Kotlin
import kotlin.reflect.IllegalPropertyAccessException
|
|
import kotlin.reflect.jvm.accessible
|
|
|
|
class A(param: String) {
|
|
protected var v: String = param
|
|
|
|
fun ref() = ::v
|
|
}
|
|
|
|
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"
|
|
}
|