AnnotatedElement — 애너테이션된 프로그램 구조 표현 인터페이스
AnnotatedElement — 애너테이션된 프로그램 구조 표현 인터페이스
AnnotatedElement는 현재 VM에서 실행 중인 프로그램의 애너테이션된 구조(annotated construct)를 나타내요. 구조(construct)는 요소(element) 또는 타입(type)이에요. 요소의 애너테이션은 선언(declaration)에, 타입의 애너테이션은 타입 이름의 특정 사용(use)에 붙어요. JLS 9.7.4에 따라 요소의 애너테이션은 선언 애너테이션(declaration annotation), 타입의 애너테이션은 타입 애너테이션(type annotation)이에요. 이 인터페이스는 애너테이션을 리플렉션으로 읽을 수 있게 해 줘요. 이 인터페이스가 반환하는 모든 애너테이션은 불변(immutable)이며 직렬화 가능해요.
본문
default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) — 지정된 유형의 애너테이션이 이 요소에 존재하면 true를 반환해요.
<T extends Annotation> T getAnnotation(Class<T> annotationClass) — 이 요소에 존재하는 지정된 유형의 애너테이션을 반환해요. 없으면 null을 반환해요.
Annotation[] getAnnotations() — 이 요소에 존재하는 모든 애너테이션을 배열로 반환해요.
default <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) — 지정된 유형의 반복 가능(repeatable) 애너테이션을 모두 반환해요.
default <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) — 이 요소에 직접 선언된 지정된 유형의 애너테이션을 반환해요. 상속받은 것은 포함하지 않아요.
default <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) — 이 요소에 직접 선언된 반복 가능 애너테이션들을 반환해요.
Annotation[] getDeclaredAnnotations() — 이 요소에 직접 선언된 모든 애너테이션을 반환해요. 상속받은 것은 포함하지 않아요.
Class, Field, Method, Constructor, Package, Parameter 등이 이 인터페이스를 구현해요. 이 인터페이스의 메서드는 애너테이션 조회 시 @Inherited 계약을 따르며, getAnnotations()는 상속받은 애너테이션도 포함해요.