Type Annotations
The Java 6 annotation syntax is useful but limited. The Type
Annotations syntax permits annotations to be written in more
places, such as generic type arguments:
List<@NonNull Object>
. Programmers can
use type annotations to write more informative types, and then
tools such as type-checkers can detect and prevent more errors.
This project is sponsored by the OpenJDK Compiler Group and is targeted for inclusion in the Java SE 7 platform.
Specification
The Type Annotations specification indicates changes to the Java language and platform.
Implementation
The OpenJDK compiler supports the Type Annotations syntax (since build M4). The version linked here has a few small differences; see its documentation for details.
- Download (includes source, platform-independent binary, and documentation)
-
Documentation
(included in the distribution; includes installation instructions) - Changelog
- Mercurial repository
Other tools that use type annotations
Several other tools already use the type annotation syntax.
- 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.
Community and getting help
Awards
- 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 Java Rock Star award for a presentation at JavaOne 2009