Why it matters

Modern Java frameworks rely heavily on annotations. Understanding is essential for framework use.

Advertisement

The architecture

Declaration: '@interface AnnotationName { ... }'.

Retention: SOURCE (compiler only), CLASS (bytecode), RUNTIME (visible via reflection).

Annotation lifecycleDeclare @annotationwith retentionApply to code@Override, @AutowiredFramework readsruntime or compileCompile-time processors generate code (Lombok); runtime reflection drives Spring
Annotations at work.
Advertisement

How it works end to end

Standard annotations: @Override, @Deprecated, @SuppressWarnings.

Framework annotations: @Autowired (Spring), @Test (JUnit), @JsonProperty (Jackson).

Annotation processing: APT/Pluggable annotation processing generates code at compile.

Meta-annotations: @Retention, @Target, @Documented control annotation behavior.