* 元注解:注解类上的注解 * @Retention(RetentionPolicy.RUNTIME):Annotation这个注解的存活时间,不写默认是源码阶段,RUNTIME是运行时阶段,就是Class字节码文件 * @Target:表示该注解可以定义在成员变量、类、方法上 * @Inherited:指定在注解可以被继承,意思就是使用了这个注解的子类也会继承这个注解 */ @Target({ElementType.FIELD,ElementType.TYPE,ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface Annotation { }
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException { Class clazz = Class.forName("anno.Student"); // 判断clazz是否有添加了注解Anno,true存在,false不存在 boolean result = clazz.isAnnotationPresent(Anno.class); }
@Anno public class Student { }
标签:clazz,Class,Anno,注解,ElementType,public From: https://www.cnblogs.com/weiduaini/p/17231821.html