findAnnotations

Platform and version requirements: JVM (1.5)
@ExperimentalStdlibApi fun <reified T : Annotation> KAnnotatedElement.findAnnotations(): List<T>
@ExperimentalStdlibApi fun <T : Annotation> KAnnotatedElement.findAnnotations(
    klass: KClass<T>
): List<T>

Returns all annotations of the given type on this element, including individually applied annotations as well as repeated annotations.

In case the annotation is repeated, instances are extracted from the container annotation class similarly to how it happens in Java reflection (java.lang.reflect.AnnotatedElement.getAnnotationsByType). This is supported both for Kotlin-repeatable (kotlin.annotation.Repeatable) and Java-repeatable (java.lang.annotation.Repeatable) annotation classes.

© 2010–2021 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/find-annotations.html