Loading…
Loading…
Topic
Articles and problems tagged Annotations.
Write a Java annotation processor: AbstractProcessor, @SupportedAnnotationTypes, processing rounds, RoundEnvironment, the javax.lang.model element API, AnnotationMirror, Filer and Messager, plus how to register processors with javac, Maven and Gradle and why Lombok is different.
Read Java annotations at runtime with the AnnotatedElement API: getAnnotation, getAnnotationsByType, declared versus inherited annotations, and three hands-on tools built with reflection, an annotation-driven toString, a mini JUnit-style test runner and a record validator.
A practical guide to Java's standard annotations: @Override, @Deprecated with since and forRemoval, @SuppressWarnings, @SafeVarargs, @FunctionalInterface, @Serial and @Generated, plus the meta-annotations @Target, @Retention, @Documented, @Inherited and @Repeatable.
Create your own Java annotations with @interface: declare elements and default values, restrict where they apply with @Target and ElementType, choose SOURCE, CLASS or RUNTIME retention, and understand the Annotation interface, proxies and dynamically computed defaults.
Learn how Java annotations work: what they are for, element syntax and defaults, value and single-element shortcuts, repeated annotations, annotating declarations, packages and record components, type-use annotations on generics and arrays, and receiver parameters.