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. Mutli 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. Mutli 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