import java.lang.annotation.Annotation; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Field; public class Test { public static void main(String[] args) throws Exception{ Class clazz= Class.forName("com.zy.test.MyDemo"); myAnn as= (myAnn) clazz.getAnnotation(myAnn.class); System.out.println(as.value()); System.out.println(as.name()); } } @myAnn(value = "aaa", name = "mydemo") class MyDemo { } //注释何时被取消 @Retention(RetentionPolicy.SOURCE) @interface myAnn { String value(); String name(); }
时间: 2024-10-24 09:32:38