I've encountered strange behaviour when trying to read Class's annotations from an object.
For example:
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
annotation class MyAnnotation(val value: String) {}
@MyAnnotation("HelloWorld")
class MyClass
// in test
val obj = MyClass()
println(obj::class.annotations) // DOESN'T finds annotation
println(obj::class.java.annotations) // finds annotation
println(obj.javaClass.annotations) // finds annotation
However, it does find it when I make direct reference to a class like so:
println(MyClass::class.annotations) // finds annotation
Anything I'm missing?
Aucun commentaire:
Enregistrer un commentaire