annotationreader.java
来自「一步 教你学会java 完成一个完整的SWT系统 是本人学习java」· Java 代码 · 共 46 行
JAVA
46 行
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 + =
减小字号Ctrl + -
显示快捷键?