samedi 30 juin 2018

Kotlin filter memberProperties by present annotation class

I've got an extension method running on Any type. On that extension method (where this refers to the target instance), I'm trying to filter the memberProperties based on annotation presence.

this::class.memberProperties
        .filter{ it.annotations.map { ann -> ann.annotationClass }.contains(ValidComponent::class)}

But it.annotations is always of size 0

Example of variable declaration on the instance: @ValidComponent var x: SomeType = constructorParam.something or @ValidComponent lateinit var x: SomeType





Aucun commentaire:

Enregistrer un commentaire