Annotations Types

Annotations Types

Annotations are declared by using following syntax

@interface AnnotationName { 
   members
} 
Members syntax
datatype memberName() [default value] 
Annotations Utilization Syntax

In java annotations are applicable for variables, methods, constructors, interfaces, another annotation, enum and classes. 

Syntax 

@AnnotationName (member1 = value1, member2 = value2,…...)

Based on annotation members, annotations are divided in to 3 types.

  1. Marker Annotation
  2. Single valued Annotation
  3. Multi valued Annotation
1. Marker Annotation

A marker annotation is a special type of annotation which contains no members.

E.g:

@Override 
2. Single valued Annotation

Single valued annotation is the annotation which contains only one member.    

E.g:

@SupressWarnings("unchecked") 
3. Multi valued Annotation

Multi valued annotation is the annotation which contains more than one member.

E.g.

@WebServlet(
        name = "MyServlet",
        description = "This is my first annotated servlet",
        urlPatterns = "/processServlet"
        )

Annotations Types

Scroll to top