Create your own Java customized annotations

Annotations is a relatively new technology, it was added to the language in Java5. An annotation is a meta data that can be attached to a java class, member, function or a parameter. It gives information about the element that is annotated. An example is the Deprecated annotation that specifies this function is old and better not used. Java5 comes with a set of annotations but you can also can create your own. In this post I will show you how to create your own annotations, use them and also refer to them during runtime. Steps for creating customized annotations: 1. Creating the annotation interface First you create the annotation interface which has specific structure. In this example the name of the annotation is ‘InvokeMultiple’ and it has 1 field ‘numberOfTimesToInvoke’. Meta-Annotations Meta annotations are actually annotations being used by annotations. @Target – specifies the type pf element this annotation is attached to. ElementType.TYPE-can be applied to any element of a class ElementType.FIELD-can be applied to a field or property ElementType.METHOD-can be applied to a method level annotation ElementType.PARAMETER-can be applied to the parameters of a method ElementType.CONSTRUCTOR-can be applied to constructors ElementType.LOCAL_VARIABLE-can be applied to local variables ElementType.ANNOTATION_TYPE-indicates that Continue reading Create your own Java customized annotations