title: Const correctness in Java using Annotations?
body: <p>Is there an existing library that allows me to annotate a Java method as @Const, so that the compiler (using apt I presume) will flag an error if it updates a field, or invokes a non-@Const method on a field; and annotate a parameter as @Const, so that the accepting method cannot invoke any of its non-@Const methods, or update any of its fields?</p>
  
  <p>(Basically, trying to add const-correctness to Java using annotations; there are some obvious details not covered in the question above, such as assigning to/from a @Const-typed parameter, etc.)</p>
  
  <p>I've found this: <a href="http://confluence.atlassian.com/pages/viewpage.action?pageId=182158080" rel="noreferrer">http://confluence.atlassian.com/pages/viewpage.action?pageId=182158080</a> but it seems like it's only available as part of IDEA.</p>
  
  <p>Following a request for clarification below, here's sample code to show what I mean:</p>
  
  <pre><code>class Person {
    private String name;
    private String address;
  
    @Const public String getName() {
      return name;
    }
  
    public void setName(String name) {
      this.name = name;
    }
  
    ... etc. for address
  }
  </code></pre>
  
  <p>Now, if I define a method such as:</p>
  
  <pre><code>void processPerson(@Const Person p)
  </code></pre>
  
  <p>a line such as: <code>p.getName()</code> would be OK in <code>processPerson</code>, since <code>getName</code> was marked as a @Const method. But calling <code>p.setName()</code> from within <code>processPerson</code> would be flagged as an error.</p>
  
  <p>Note that this is very different from <code>final</code>: if the parameter was defined as <code>final Person p</code>, any assignment to <code>p</code> would have been illegal, but it's still perfectly valid to modify what <code>p</code> refers to (either using <code>p.setName(...)</code> or even more directly, with <code>p.name = ...</code>.</p>