Annotations
Annotations, a form of metadata, provide data about a program that is not part of the program itself. Annotations have no direct effect on the operation of the code they annotate.
Annotations have a number of uses, among them:
- Information for the compiler — Annotations can be used by the compiler to detect errors or suppress warnings.
- Compile-time and deployment-time processing — Software tools can process annotation information to generate code, XML files, and so forth
- Runtime processing — Some annotations are available to be examined at runtime.
Annotations Basics
-
The Format of an Annotation
- In its simplest form, an annotation looks like the following:
@Entity
- Repeating annotations are supported as of the Java SE 8 release
@Author(name = "Jane Doe") @Author(name = "John Smith") class MyClass { ... }
- In its simplest form, an annotation looks like the following:
-
Where Annotations Can Be Used
Annotations can be applied to declarations: declarations of classes, fields, methods, and other program elements. When used on a declaration, each annotation often appears, by convention, on its own line.