Annotations and Annotation Types

Started by VelMurugan, Aug 18, 2008, 11:26 AM

Previous topic - Next topic

VelMurugan

Annotations and Annotation Types

Annotations are notes in Java programs to instruct the Java compiler to do something. Java provides three standard annotations and four standard meta-annotations.

   1. An annotation type is a special interface type.
   2. An annotation is an instance of an annotation type.
   3. An annotation type has a name and members.
   4. The information contained in an annotation takes the form of key/value pairs.
   5. There can be zero or multiple pairs and each key has a specific type.
   6. It can be a String, int, or other Java types.
   7. Annotation types with no key/value pairs are called marker annotation types.
   8. Those with one key/value pair are referred to single-value annotation types.

   1. There are three annotation types in Java 5: Deprecated, Override, and Suppress Warnings.
   2. There are four other annotation types that are part of the java.lang.annotation package: Documented, Inherited, Retention, and Target.
   3. These four annotation types are used to annotate annotations

The Annotation Interface


   1. An annotation type is a Java interface.
   2. All annotation types are subinterfaces of the java.lang.annotation.Annotation interface.
   3. It has one method, annotation Type, that returns an java.lang.Class object.

java.lang.Class<? extends Annotation> annotationType()

In addition, any implementation of Annotation will override the equals, hashCode, and toString methods from the java.lang.Object class.