import java.lang.annotation.*;
public @interface MyAnnotation {
}
public class MyClass {
public void myMethod() {
}
}
public class Main {
public static void main(String[] args) {
MyClass obj = new MyClass();
Class<?> cls = obj.getClass();
Method method;
try {
method = cls.getMethod("myMethod");
MyAnnotation annotation = method.getAnnotation(MyAnnotation.class);
String value = annotation.value();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
}