import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface MyAnnotation { String message(); } public class MyClass { public void myMethod() { } } import java.lang.reflect.Method; public class AnnotationDemo { public static void main(String[] args) throws NoSuchMethodException { Method method = MyClass.class.getMethod("myMethod"); MyAnnotation annotation = method.getAnnotation(MyAnnotation.class); System.out.println(annotation.message()); } }


上一篇:
下一篇:
切换中文