Java Custom Annotations – Read using Reflection API

After reading this article , you will be able to create an Annotation in Java and Read the annotations using Java Reflection API.

Java Annotations can be created as follows :

Custom Annotations Example :

 

Contents at glance

MyMethodAnnotation.java – Custom Annotation for methods
MyClassAnnotation.java – Custom Annotation for Class
MyClassWithAnnotations.java – Class having methods annotated with custom annotations
ReadAnnotationsUsingReflection.java – Read annotation using Java Reflection API

MyMethodAnnotation.java

MyClassAnnotation.java

MyClassWithAnnotations.java

ReadAnnotationsUsingReflection.java

OUTPUT

Class : MyClassWithAnnotations , rootPath = /employee
method : getName , path : /getname , returnType = json
method : getResourceType , path : /getResourceType , returnType = text

 

References :

https://docs.oracle.com/javase/tutorial/java/annotations/declaring.html

http://docs.oracle.com/javase/1.5.0/docs/guide/language/annotations.html

https://docs.oracle.com/javase/tutorial/java/annotations/basics.html

 

Author of CodeForEach.com . Loves coding and related technologies.
 

www.000webhost.com