Class: Annotation[] getAnnotations()
import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation {
String stringValue();
int intValue();
}
@Retention(RetentionPolicy.RUNTIME)
@interface What {
String description();
}
@What(description = "An annotation test class")
@MyAnnotation(stringValue = "for class", intValue = 100)
public class Main {
@What(description = "An annotation test method")
@MyAnnotation(stringValue = "Annotation Example", intValue = 100)
public static void myMethod(String str, int i) {
}
public static void main(String[] arg) throws Exception {
Main ob = new Main();
Annotation[] annos = ob.getClass().getAnnotations();
System.out.println("All annotations for Meta2:");
for (Annotation a : annos)
System.out.println(a);
}
}
Related examples in the same category