Define new annotation type : Annotations Create « Language « Java Tutorial

  1. All annotation types automatically extend the Annotation interface.
  2. Annotation is a super-interface of all annotations.
  3. It overrides hashCode( ), equals( ), and toString() defined by Object.
  4. It defines annotationType( ), which returns a Class object that represents the invoking annotation.
  5. When you apply an annotation, you give values to its members.
// A simple annotation type.
@interface MyAnnotation {
  String stringValue();

  int intValue();

public class MainClass {
  // Annotate a method.
  @MyAnnotation(stringValue = "Annotation Example", intValue = 100)
  public static void myMethod() {


1.11.Annotations Create
1.11.1.Creating Annotations
1.11.2.Define new annotation type
1.11.3.Specifying a Retention Policy
1.11.4.default values in an annotation.