Declaring an annotation
suggest changeAnnotations are a means of attaching metadata to code. To declare an annotation, put the annotation modifier in front of a class:
annotation class Strippable
Annotations can have meta-annotations:
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.EXPRESSION)
annotation class Strippable
Annotations, like other classes, can have constructors:
annotation class Strippable(val importanceValue: Int)
But unlike other classes, an annotation constructor is limited to the following types:
- types that correspond to Java primitive types (
Int,Long, and so on) - strings
- classes (
Foo::class) - enums
- other annotations
- arrays of the types listed above
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents