Generate separate anonymous class for each property reference
Each property reference obtained by the '::' operator now causes back-end to generate an anonymous subclass of the corresponding KProperty class, with the customized behavior. This fixes a number of issues: - get/set/name of property references now works without kotlin-reflect.jar in the classpath - get/set/name methods are now overridden with statically-generated property access instead of the default KPropertyImpl's behavior of using Java reflection, which should be a lot faster - references to private/protected properties now work without the need to set 'accessible' flag, because corresponding synthetic accessors are generated at compile-time near the target property #KT-6870 Fixed #KT-6873 Fixed #KT-7033 Fixed
This commit is contained in:
+29
@@ -0,0 +1,29 @@
|
||||
import kotlin.reflect.IllegalPropertyAccessException
|
||||
import kotlin.reflect.KProperty1
|
||||
import kotlin.reflect.jvm.accessible
|
||||
|
||||
class Result {
|
||||
private val value = "OK"
|
||||
|
||||
fun ref() = Result::class.properties.single() as KProperty1<Result, String>
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user