jeudi 27 octobre 2022

Get annotation value via reflection

I am trying to get all the "Keys" of annotations for use later, I am initializing the value like this:

private val wgKeys = SpecialRequestContext::class.members.associate { m ->
    m.name to run {
        val headerAnnotation = m.annotations.find { a -> a is Header } as? Header
        headerAnnotation?.key
    }
}

Unfortunately, the result is a Map with name for keys (correct), but all the values are null. While debugging I see that m.annotations has no values.

Are annotations not available at this step?





Aucun commentaire:

Enregistrer un commentaire