Mega Code Archive

 
Categories / Java Tutorial / Language
 

Define new annotation type

All annotation types automatically extend the Annotation interface. Annotation is a super-interface of all annotations. It overrides hashCode( ), equals( ), and toString() defined by Object. It defines annotationType( ), which returns a Class object that represents the invoking annotation. 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() {   } }