📄 annotationreader.java
字号:
import java.lang.annotation.*;import java.lang.reflect.*;/** * 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(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -