Type Annotations
JSR 308 (Annotations on Java Types) extends the Java language so that annotations may appear on essentially any use of a type.
JSR 308 is part of JSR 337 (Java SE 8). An Early Draft Review of the specification for JSR 308 was published in January 2012.
The OpenJDK Type Annotations Project is sponsored by the Compiler Group to host an implementation of JSR 308 suitable for inclusion in JDK 8, the Reference Implementation of Java SE 8.
The scope of the implementation is given in JDK Enhancement Proposal 104 (Annotations on Java Types).
The implementation is discussed on the type-annotations-dev mailing list. (Previously on jsr308-discuss.) Please note this list is solely for implementation issues, and not for general issues with the design of annotations in Java.
Implementation
-
Download (includes source, platform-independent binary, and documentation)
Tools that use type annotations
Several tools use the type annotation syntax proposed by JSR 308:
-
The Checker Framework makes it easy to write and use compiler plug-ins that implement a custom type system. The compiler plug-in enables a programmer to find bugs or to verify their absence. The Checker Framework comes with several type-checking plug-ins that you can try right away.
-
Inference tools automatically add annotations to your code, making it even easier to start using the checkers. You must download these tools separately.
-
To infer the @Nullable type qualifier, use Daikon
-
To infer the
@NonNull
type qualifier, use the Julia Analyzer, Nit, or JastAdd -
To infer the
@ReadOnly
type qualifier, use Javarifier
-
-
Annotation file utilities extract annotations from, and write annotations to,
.java
and.class
files.
Awards for JSR 308
-
Won the Most Innovative Java SE/EE JSR of the Year award in 2007.
-
Nominated for the Most Outstanding Spec Lead for Java SE/EE award in 2008.
-
Won a Rock Star award for a presentation at JavaOne 2009.