import java.lang.annotation.*; /** * Read annotation information from a class at runtime using the new * JDK1.5 reflection features **/ public class AnnotationReader { AnnotatedClass ac; /** * Constructor **/ public AnnotationReader() { ac = new AnnotatedClass(); } /** * Print out runtime annotation information **/ public void printAnnotations() { Class c = ac.getClass(); Annotation[] annotations = c.getAnnotations(); int numberOfAnnotations = annotations.length; System.out.println("Class " + c.getName() + " has " + numberOfAnnotations + " annotations"); for (int i = 0 ; i < numberOfAnnotations; i++) { System.out.println("Annotation " + i + ": " + annotations[i] + ", type" + annotations[i].annotationType().getName()); } } /** * Main entry point * * @param args Command line arguments **/ public static void main(String[] args) { AnnotationReader ar = new AnnotationReader(); ar.printAnnotations(); } }