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

 

 

Submit a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

www.000webhost.com