Lesson content
Read, practise, then check your understanding
Annotations attach metadata to declarations and type uses. Meta-annotations control where metadata is legal and how long it remains.
A runtime annotation
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Audited {
String action();
}
@Audited(action = "user.read")
public User find(long id) { return repository.find(id); }
SOURCE annotations support tooling, CLASS annotations remain in bytecode, and RUNTIME annotations are reflectively visible. Repeatable and inherited annotations have specific rules. Compile-time processors can validate models and generate sources without runtime reflection. Treat annotations as declarative metadata, not hidden control flow that makes behavior impossible to trace.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.