fork(3) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.lang.annotation.*;
  4. import java.lang.reflect.Method;
  5.  
  6. class MyTest
  7. {
  8. public static void main(String[] args)
  9. {
  10. for (final Method method : MyClass.class.getDeclaredMethods())
  11. {
  12. if (method.getAnnotation(MyAnnotation.class) != null)
  13. {
  14. System.out.println(String.format("@MyAnnotation %s.%s", method.getDeclaringClass().getSimpleName(), method.getName()));
  15. }
  16. }
  17. }
  18. }
  19.  
  20. @Documented
  21. @Inherited
  22. @Retention(RetentionPolicy.RUNTIME)
  23. @Target(ElementType.METHOD)
  24. @interface MyAnnotation
  25. {
  26. }
  27.  
  28. interface MyGenericInterface<T>
  29. {
  30. void hello(T there);
  31. }
  32.  
  33. class MyClass implements MyGenericInterface<String>
  34. {
  35. @MyAnnotation
  36. @Override
  37. public void hello(String there)
  38. {
  39. }
  40. }
  41.  
Success #stdin #stdout 0.13s 320448KB
stdin
Standard input is empty
stdout
@MyAnnotation MyClass.hello
@MyAnnotation MyClass.hello