title: Can I make a constructor for a custom annotation?
body: <p>I am trying to make an annotation for different methods and classes to programmatically keep track of all the rules, so I can display them to the user.</p>
  
  <p>I would like the annotation class <code>Rule</code> to record all the places that the annotation is used. As a first step, I tried adding a single static counter to the class, here's what the <code>Rule</code> annotation looks like:</p>
  
  <pre><code>public @interface Rule {
      static int count = 0;
      String name();
      String description(); //Note the parentheses
  
      public Rule(String name, String description) {
          count++;
  
          this.name = name;
          this.description = description;
      }
  }
  </code></pre>
  
  <p>The way I would use it is like this:</p>
  
  <pre><code>public class Airline {
      private String code;
  
      @Rule(name = "Formatted Code", description = "e.g. Format 'la' as 'LA'")
      public String codeFormatted() {
          return code.toUpperCase();
      }
  
      public static void main(String args[]) {
          System.out.println(Rule.count);
      }
  }
  </code></pre>
  
  <p>Without the <code>Rule</code> public constructor, this compiles using <code>javac</code> version 1.8.0_162.</p>
  
  <p>When I add the public constructor (to increment Rule.count), I get compiler errors:</p>
  
  <pre><code>javac Rule.java
  Rule.java:6: error: &lt;identifier&gt; expected
      public Rule(String name, String description) {
                ^
  1 error
  
  Compilation exited abnormally with code 1 at Thu Mar 22 19:58:39
  </code></pre>
  
  <p>What am I missing in my <code>Rule</code> constructor?</p>
  
  <p>Or, is this a completely ridiculous idea and I should feel bad? I can't tell, still getting used to annotations.</p>