Meta Annotations

Explore key Kotlin meta-annotations, their usage, and a special syntax for annotating code elements.

Annotations that are used to annotate other annotations are known as meta-annotations. There are four key meta-annotations from Kotlin stdlib:

  • Target: It indicates the kinds of code elements that are possible targets of an annotation. As arguments, it accepts AnnotationTarget enum values, which include values like CLASS, PROPERTY, FUNCTION, etc.

  • Retention: It determines whether an annotation is stored in the binary output of compilation and is visible for reflection. By default, both are true.

  • Repeatable: It determines that an annotation is applicable twice or more in a single code element.

  • MustBeDocumented: It determines that an annotation is part of a public API and should therefore be included in the generated documentation for the element to which the annotation is applied.

Here are example usages of some of these annotations:

Get hands-on with 1400+ tech skills courses.