~/ learn/ java-from-zero/ cards/ Meta-annotations: @Retention, @Target, @Documented, @Inherited, @Repeatable
1 of 4

Type @Retention(RUNTIME) and @Target on a custom annotation

Type @Retention(RUNTIME) and @Target on a custom annotation

Answer

@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Audited {}

RUNTIME retention is required for reflection to see the annotation at runtime. @Target(METHOD) limits where it can be applied — the compiler rejects it on a class or field.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/e17f6566-5fd0-4dc0-a6b0-8b23459362fb/flashcard utf-8 LF