February 2018
Intermediate to advanced
350 pages
7h 35m
English
Annotations are a way to attach meta info to your code (such as documentation, configuration, and others).
Let's look at the following example code:
annotation class Tasty
An annotation itself can be annotated to modify its behavior:
@Target(AnnotationTarget.CLASS)@Retention(AnnotationRetention.RUNTIME)annotation class Tasty
In this case, the Tasty annotation can be set on classes, interfaces, and objects, and it can be queried at runtime.
For a complete list of options, check the Kotlin documentation.
Annotations can have parameters with one limitation, they can't be nullable:
@Target(AnnotationTarget.CLASS)@Retention(AnnotationRetention.RUNTIME)annotation class Tasty(val tasty:Boolean = true)@Tasty(false)object ElectricOven ...
Read now
Unlock full access