Java Annotation

Introduction

Java annotation is created via the interface.

The following code creates an annotation called MyAnno:

// A simple annotation type.  
@interface MyAnno {
  String str();

  int val();
}

When applying an annotation, assign values to its members.

The following code applied MyAnno to a method declaration:

// Annotate a method.
@MyAnno(str = "Annotation Example", val = 100)
public static void myMethod() {



PreviousNext

Related