Java Reflection: Annotations
What are Java Annotations? Annotations is a new feature from Java 5. Annotations are a kind of comment or meta data you can insert in your Java code. These annotations can then be processed at compile time by pre-compiler tools, or at runtime via Java Reflection. The annotation can be attached to Classes, Methods,Parameters,Fields etc. How to create custom Annotation? To create an annotation we use the interface keyword and add an @ symbol infront of it. The @ symbol will tell the compiler that it doing some business with an annotation. @Retention (RetentionPolicy.RUNTIME) public @interface MyAnnotation { String value(); } The @ in front of the interface marks it as an annotation. Once you have defined the annotation you can use it in your code.Here is an example of class annotation: @MyAnnotation(value="Class Annotation") public class MyClass { } The two directives in the annotation definition, @Retention(RetentionPolicy.RUNTIME) and @Target(El...