~/ 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/9bf4ac62-e755-4d28-abb4-e97b84c794cb/flashcard utf-8 LF