https://kotlinlang.org logo
#reflect
Title
# reflect
i

iamthevoid

11/02/2020, 6:40 AM
Hey, there! Does anybody knows why property
annotations
for
KClass
returns empty array?
Hmmm, btw i just tried to call
ActionBarContainer::class.java.annotations
and it returns empty array too
g

gildor

11/02/2020, 7:21 AM
on which context do you call it? on runtime? If so, it’s expected, RestrictTo has CLASS Retention policy, so it doesn’t exist on runtime, only in bytecode
i

iamthevoid

11/02/2020, 8:42 AM
I am not sure ( I'll tried to create a
Generator
, which runs by launch
fun main
and works with android sdk classes by reflection, but after many fails with
kts
scripts and pure java library i've created android library (to access android View classes with reflection) I launch my Generator by click
play
in AS interface. Assume it may be a runtime. Depends on how this
main
launches
g

gildor

11/02/2020, 8:43 AM
yes, it’s on runtime, so you do not work with bytecode So you cannot get RestrictTo annotation, it’s not a part of runtime, it exist only in sources and bytecode
i

iamthevoid

11/02/2020, 8:48 AM
maybe you know what (and how) i should do to reach that annotation? I assume that i must create pure java library and find a way to access android sdk classes? Or there
ClassLoader
can help to save my life?
g

gildor

11/02/2020, 9:30 AM
No, you have to read it from .class file (or .dex if it Android)
2 Views