October 2019
Intermediate to advanced
434 pages
11h 54m
English
If a use-site is not specified for an added annotation, the target will be chosen based on the targets specified on the annotation.
Let's look at the following custom annotation:
@Target(AnnotationTarget.PROPERTY_GETTER)annotation class ColorRes
This annotation can be applied to property getters, but not other targets. Therefore, in this example, the code will not compile:
class ViewModel( @ColorRes val resId:Int ) . // will not compile
However, if we specify the get use-site, then the code will compile just fine:
class ViewModel( @get:ColorRes val resId:Int )
If an annotation declaration doesn't include the @Target annotation, the following targets will be applicable:
Read now
Unlock full access