Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mypackage;
- public class MyClass{
- @myAnnotation
- public static void one() {
- System.out.println("1");
- }
- @myAnnotation
- public static void two() {
- System.out.println("2");
- }
- package mysecondpackage;
- public class MySecondClass{
- public static void runAllAnnotatedWith() throws Exception {
- final Class<?> c= Class.forName("mypackage.MyClass");
- final Method[] m= c.getDeclaredMethods();
- for (final Method method : m)
- {
- if (method.isAnnotationPresent(myAnnotation.class))
- {
- method.invoke(null);
- }
- }
- 1
- 2
- 3
Add Comment
Please, Sign In to add comment