Hi! I wonder if using kotlin delegates automatical...
# announcements
d
Hi! I wonder if using kotlin delegates automatically means using reflection mechanisms. They have KProperty and all... Reflection brings performance costs on Android, that's why I am concerned about this.
m
dimsuz:
KProperty
is just an interface which is an easy template for writing new delegates. Kotlin (unlike Groovy, for example) compiles statically, without any sudden reflection. Delegate is just an object who takes responsibility for storing a value.
d
oh, so If i use
KProperty::name
in my delegate this won't end up in reflection calls?
m
Kotlin reflection != Java reflection. Using KProperties leads to synthetic class generation, not to runtime annotation lookup.
d
Nice! Can I read more about this generation somewhere?
m
I don’t know, decompiler is my guide to Kotlin bytecode world 🙂 You can try out Tools -> Kotlin -> Show Kotlin Bytecode if you’re familiar with the JVM bytecode syntax.
d
yep, I did decompile my delegate, but I guess I should try to decompile a class which uses it. thanks for the hint 🙂
m
You may want to look at getter/setter code which uses synthetic classes directly.