title: Multiple annotations of the same type on one element?
body: <p>I'm attempting to slap two or more annotations of the same type on a single element, in this case, a method. Here's the approximate code that I'm working with:</p>
  
  <pre><code>public class Dupe {
      public @interface Foo {
        String bar();
      }
  
      @Foo(bar="one")
      @Foo(bar="two")
      public void haha() {}
  }
  </code></pre>
  
  <p>When compiling the above, javac complains about a duplicate annotation:</p>
  
  <pre>
  max@upsight:~/work/daybreak$ javac Dupe.java 
  Dupe.java:5: duplicate annotation
  </pre>
  
  <p>Is it simply not possible to repeat annotations like this? Pedantically speaking, aren't the two instances of @Foo above different due to their contents being different?</p>
  
  <p>If the above isn't possible, what are some potential workarounds?</p>
  
  <p>UPDATE: I've been asked to describe my use case. Here goes.</p>
  
  <p>I'm building a syntax sugarish mechanism to "map" POJOs to document stores such as MongoDB. I want to allow indexes to be specified as annotations on the getters or setters. Here's a contrived example:</p>
  
  <pre><code>public class Employee {
      private List&lt;Project&gt; projects;
  
      @Index(expr = "project.client_id")
      @Index(expr = "project.start_date")
      public List&lt;Project&gt; getProjects() { return projects; }
  }
  </code></pre>
  
  <p>Obviously, I want to be able to quickly find instances of Employee by various properties of Project. I can either specify @Index twice with different expr() values, or take the approach specified in the accepted answer. Even though Hibernate does this and it's not considered a hack, I think it still makes sense to at least allow having multiple annotations of the same type on a single element.</p>