Guest User

Untitled

a guest
Jan 3rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. package mypackage;
  2. public class MyClass{
  3.  
  4. @myAnnotation
  5. public static void one() {
  6. System.out.println("1");
  7. }
  8.  
  9. @myAnnotation
  10. public static void two() {
  11. System.out.println("2");
  12. }
  13.  
  14. package mysecondpackage;
  15. public class MySecondClass{
  16.  
  17. public static void runAllAnnotatedWith() throws Exception {
  18. final Class<?> c= Class.forName("mypackage.MyClass");
  19. final Method[] m= c.getDeclaredMethods();
  20. for (final Method method : m)
  21. {
  22. if (method.isAnnotationPresent(myAnnotation.class))
  23. {
  24. method.invoke(null);
  25. }
  26. }
  27.  
  28. 1
  29. 2
  30. 3
Add Comment
Please, Sign In to add comment