내가 이렇게 내 자신의 주석 형을 만들었습니다자바에서 클래스 주석을 얻는 방법은 무엇입니까?
public @interface NewAnnotationType {}
및 클래스에 연결 :
@NewAnnotationType
public class NewClass {
public void DoSomething() {}
}
와 나는이 같은 반사를 통해 클래스 주석을 얻으려고 노력 :
Class newClass = NewClass.class;
for (Annotation annotation : newClass.getDeclaredAnnotations()) {
System.out.println(annotation.toString());
}
하지만 아무 것도 인쇄하지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까?
때문에 주석이 컴파일시에만 사용할 수 있습니다. –