Java Reference
In-Depth Information
Summary
Annotations are types in Java. They are used to associate information to the declarations of program elements or type
uses in a Java program. Using annotations does not change the semantics of the program.
Annotations can be available in the source code only, in the class files, or at runtime. Their availability is
controlled by the retention policy that is specified when the annotation types are declared.
There are two types of annotations: regular annotation or simply annotations, and meta-annotations.
Annotations are used to annotate program elements whereas meta-annotations are used to annotate other
annotations. When you declare an annotation, you can specify its targets that are the types of program elements that it
can annotate. Prior to Java 8, annotations were not allowed to be repeated on the same element. Java 8 lets you create
a repeatable annotation.
Java library contains many annotation types that you can use in your Java programs; Deprecated , Override ,
SuppressWarnings , FunctionalInterface , etc. are a few of the commonly used annotation types. They have compiler
support, which means that the compiler generates errors if the program elements annotated with these annotations
do not adhere to specific rules.
Java lets you write annotation processors that can be plugged into the Java compiler to process annotations when
Java programs are compiled. You can write processors to enforce custom rules based on annotation.
 
Search WWH ::




Custom Search