Using Annotations
Annotate code.
What Are Annotations?
Annotations attach metadata to code. They do not change behavior by themselves, but tools, compilers, and libraries read them to make decisions.
You write an annotation with @ followed by its name, placed right before the element it applies to.
A First Annotation
The standard library ships several useful annotations. @Deprecated marks code that should no longer be used and shows a warning at the call site.
@Deprecated("Use newGreet() instead")
fun greet() = "Hi"
fun newGreet() = "Hello"
fun main() {
println(newGreet())
}All lessons in this course
- Using Annotations
- Defining Annotations
- Reflection Basics
- Practical Reflection