A repeatable annotation in Kotlin is a custom annotation configured with theDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
@kotlin.annotation.Repeatable meta-annotation, allowing it to be applied multiple times to the exact same target element (such as a class, function, or property) within a single declaration.
Declaration and Syntax
To define a repeatable annotation, apply the@Repeatable meta-annotation to an annotation class. Kotlin automatically handles the generation of the underlying container annotation required to group multiple instances.
Compiler Mechanics and Retention
When the Kotlin compiler encounters multiple instances of a repeatable annotation, it implicitly generates a container annotation to hold the array of annotation instances.- Native Support: Since Kotlin 1.6, repeatable annotations are supported natively. The compiler automatically generates a nested
Containerannotation (e.g.,Tag.Container) to hold the array of values. - Retention Policies: Kotlin’s native
@kotlin.annotation.Repeatablefully supports all retention policies, includingAnnotationRetention.SOURCE,AnnotationRetention.BINARY, andAnnotationRetention.RUNTIME.
Java Interoperability
Kotlin’s native@kotlin.annotation.Repeatable automatically makes the annotation repeatable in Java. The Kotlin compiler achieves this by implicitly generating the nested Container annotation class, which Java 8+ recognizes as the standard container for the repeatable annotation.
The @JvmRepeatable meta-annotation is only required if you must specify a custom explicit container class. This is typically necessary only for backward compatibility with an existing Java codebase that expects a specific, pre-defined container annotation name rather than Kotlin’s default nested Container.
Runtime Retrieval via Reflection
To extract multiple instances of a repeatable annotation at runtime, use thefindAnnotations<T>() extension function from the kotlin.reflect.full package. This function automatically unwraps the implicit or explicit container and returns a list of the annotation instances.
Master Kotlin with Deep Grasping Methodology!Learn More





