Class: Method getMethod(String name, Class>... parameterTypes)
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation {
String stringValue();
int intValue();
}
public class Main {
@MyAnnotation(stringValue = "Annotation Example", intValue = 100)
public static void myMethod() {
}
public static void main(String[] a) throws Exception {
Main ob = new Main();
Class c = ob.getClass();
Method m = c.getMethod("myMethod");
MyAnnotation anno = m.getAnnotation(MyAnnotation.class);
System.out.println(anno.stringValue() + " " + anno.intValue());
}
}
Related examples in the same category