Type Annotations (JSR-308) Support

As you all know, JDK 7 includes new java syntax for Annotations on Types (JSR-308)

To enable JSR-308 support in Maia, set the Java language level level to 7:

Then you can declare and use your weird type annotations almost everywhere:

To enable type annotations compilation in IntelliJ IDEA, download the latest Open JDK build, patch it as described in Type Annotations Prototype Implementation FAQ, and attach it to an IntelliJ IDEA project via Project SDK on Project tab in the Project Structure dialog (Ctrl+Alt+Shift+S).

Comments below can no longer be edited.

4 Responses to Type Annotations (JSR-308) Support

  1. Avatar

    Eugene Kirpichov says:

    August 9, 2009

    Thank you! I am craving for a release of JDK7 to finally beat the hell out of bugs in my programs 🙂

  2. Avatar

    Nick Fortescue says:

    December 23, 2010

    I’m using IntelliJ 10. Is there a currently recommended way to enable type annotations compilation? I know JSR-308 has now been postponed to Java 8. I can see that the Project language level now says Annotations under Java 8.

    However, the instructions for patching the type annotations compiler no longer work. The recommended way of installing seems to be downloading the checker framework, and using the javac there. However, setting the project SDK insists on it being a JSDK or an IntelliJ IDEA plugin SDK, which doesn’t work with the javac for the JSR-308 project.

    Is there any way in IntelliJ I can do what the javac/javac.bat scripts do and set the bootclasspath to be jsr308-all.jar?

  3. Avatar

    Nick Fortescue says:

    December 23, 2010

    I’ve found a workaround. For those also with this problem they might want to look at: http://blog.nickfortescue.com/2010/12/jsr308-type-annotations-compiler.html

  4. Avatar

    Koros says:

    August 25, 2015

    Really useful thanks.

Discover more