According to the Kotlin language spec, there are three types of annotation retention:
- Source retention (accessible by source-processing tools);
- Binary retention (retained in compilation artifacts);
- Runtime retention (accessible at runtime).
Looking at the KDoc for kotlin-stdlib on the JVM we get the following:
public enum class AnnotationRetention {
/** Annotation isn't stored in binary output */
SOURCE,
/** Annotation is stored in binary output, but invisible for reflection */
BINARY,
/** Annotation is stored in binary output and visible for reflection (default retention) */
RUNTIME
}
I can understand the use cases for SOURCE (available for inspection by annotation processors) and RUNTIME (available for inspection using reflection) but I cannot understand a use case for BINARY.
Can someone please explain a use case for this type of retention? Why would I choose BINARY over SOURCE if I don't need RUNTIME?
