While developing a Java application, you might want to annotate, or associate metadata (data that describes other data) with, various application elements. For example, you might want to identify methods that are not fully implemented so that you will not forget to implement them. Java's annotations language feature lets you accomplish this task.
This section introduces you to annotations. After defining this term and presenting three kinds of compiler-supported annotations as examples, the section shows you how to declare your own annotation types and use these types to annotate source code. Finally, you discover how to process your own annotations to accomplish useful tasks.
NOTE: Java has always supported ad hoc annotation mechanisms. For example, the java.lang.Cloneable interface identifies classes whose instances can be shallowly cloned via Object's clone() method, the transient reserved word marks fields that are to be ignored during serialization, and the @deprecated javadoc tag documents methods that are no longer supported. In contrast, the annotations feature is a standard for annotating code.
Was this article helpful?