Chapter 6. Annotations

One of the more popular terms being tossed around in programming these days is metadata. Metadata is simply information about information. It resides somewhere in the spectrum between Java source code, which is raw information for a compiler, and JavadocJavadoc, which is pure documentation. Metadata typically makes statements about source code that is interpreted at some point, usually by a code or data analysis tool.

Your first thought might be, “Well, Javadoc takes care of that, right?” Consider this—how many ways are there to say, “This variable should not be null.” In Javadoc, you might say “non-null,” you might say “This variable shouldn’t be null,” you might say “Don’t assign null to this.” All are valid in terms of documentation, but there is no consistency among them. There isn’t any tool that could analyze and account for all the variances in how you might state this simple condition. Annotations, new to Tiger, seek to solve that problem by providing a well-defined metadata mechanism.

In a nutshell, annotations are modifiers that can be applied to package and type declarations, ...

Get Java 5.0 Tiger: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.