title: Repeatable annotations in Java 8
body: <pre><code>// Demonstrate a repeated annotation.
  
  import java.lang.annotation.*;
  import java.lang.reflect.*;
  
  // Make MyAnno repeatable.
  @Retention(RetentionPolicy.RUNTIME)
  @Repeatable(MyRepeatedAnnos.class)
  @interface MyAnno {
      String str() default "Testing";
      int val() default 9000;
  }
  
  // This is the container annotation.
  @Retention(RetentionPolicy.RUNTIME)
  @interface MyRepeatedAnnos {
      MyAnno[] value();
  }
  
  class RepeatAnno {
  
      // Repeat MyAnno on myMeth().
      @MyAnno(str = "First annotation", val = -1)
      @MyAnno(str = "Second annotation", val = 100)
      public static void myMeth(String str, int i) {
          RepeatAnno ob = new RepeatAnno();
          try {
              Class&lt;?&gt; c = ob.getClass();
              // Obtain the annotations for myMeth().
              Method m = c.getMethod("myMeth", String.class, int.class);
              // Display the repeated MyAnno annotations.
              Annotation anno = m.getAnnotation(MyRepeatedAnnos.class);
              System.out.println(anno);
          } catch (NoSuchMethodException exc) {
              System.out.println("Method Not Found.");
          }
      }
  
      public static void main(String args[]) {
          myMeth("test", 10);
      }
  }
  </code></pre>
  
  <p>I have copy-pasted this code from a book and I tried to run this code in my system with JDK version <em>1.8.0_131</em>, but I'm getting the following compilation error:</p>
  
  <blockquote>
  <pre><code>error: cannot find symbol
  @Repeatable(MyRepeatedAnnos.class)
   ^
    symbol: class Repeatable
  RepeatAnno.java:19: error: duplicate annotation
  @MyAnno(str = "Second annotation", val = 100)
  ^
  2 errors
  </code></pre>
  </blockquote>
  
  <p>I can't understand what is wrong here.
  Please help.</p>