Hey can someone explain what is the use of ```@Ret...
# android
v
Hey can someone explain what is the use of
Copy code
@Retention(AnnotationRetention.BINARY)
What is
Retention
,
AnnotationRetention
and
BINARY
?
z
This is required if you want to define your own annotations (or you want to know how an existing one behaves). The
@Retention
annotation controls whether usages an annotation are preserved when the code is compiled from source to binary. This matters if you want to keep the information about something being annotated available for runtime (for example, to read the annotation information using reflection).
AnnotationRetention
is a simple enum that contains the available retention options. See the docs which list the available options (source, binary, runtime) and explain what they mean: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.annotation/-annotation-retention/
v
@zsmb what is reflection in this line
Annotation is stored in binary output, but invisible for reflection
z
This page explains reflection in the context of Kotlin: https://kotlinlang.org/docs/reflection.html In short, it’s a way to inspect your program (e.g. classes) at runtime.
v
ok got it thanks