Meta Annotations
Explore key Kotlin meta-annotations, their usage, and a special syntax for annotating code elements.
We'll cover the following
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 acceptsAnnotationTarget
enum
values, which include values likeCLASS
,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 aretrue
.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.