Field Class , . Field, # getType. , , Field s.
Processor.java
public class Processor {
public static void main(String[] args) {
Class<?> clazz = AnotherAnnotatedClass.class;
Field[] fields = clazz.getDeclaredFields();
for(Field f:fields){
if(f.getType().isAnnotationPresent(ClassAnnotation.class)){
System.out.println(f.getName());
}
}
}
}
ClassAnnotation.java
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ClassAnnotation {
}
AnnotatedClass.java
@ClassAnnotation
public class AnnotatedClass {
}
AnotherAnnotatedClass.java
@ClassAnnotation
public class AnotherAnnotatedClass {
private AnnotatedClass annotatedClass;
private int intIsNotAnnotated;
}