fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.lang.annotation.ElementType;
  7. import java.lang.annotation.Inherited;
  8. import java.lang.annotation.Retention;
  9. import java.lang.annotation.RetentionPolicy;
  10. import java.lang.annotation.Target;
  11. import java.lang.annotation.Annotation;
  12.  
  13. /* Name of the class has to be "Main" only if the class is public. */
  14. class Ideone
  15. {
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. Class<?> clazz = MySecondInterface.class;
  19.  
  20. Retriable annotation = clazz.getAnnotation(Retriable.class);
  21. System.out.println("Retriable annotation: " + annotation);
  22.  
  23. Annotation[] annotations = clazz.getAnnotations();
  24. System.out.println("Annotations: " + Arrays.toString(annotations));
  25.  
  26. annotations = clazz.getDeclaredAnnotations();
  27. System.out.println("Declared Annotations: " + Arrays.toString(annotations));
  28. }
  29.  
  30. }
  31.  
  32. @Retriable
  33. interface MyInterface {
  34. public void myMethod();
  35. }
  36.  
  37. interface MySecondInterface extends MyInterface {
  38.  
  39. }
  40.  
  41.  
  42.  
  43. @Inherited
  44. @Retention(RetentionPolicy.RUNTIME)
  45. @Target(ElementType.TYPE)
  46. @interface Retriable {
  47.  
  48. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
Retriable annotation: null
Annotations: []
Declared Annotations: []