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());
}
}