jeudi 22 janvier 2015

How to read the annotations defined on return type of a Method programmatically

How can we read the annotations defined on return type of a Method programmatically?


I tried looking for methods in java.lang.reflect.Method but I could only find the ways to read the class type of the return value or read the generic information.Is there a method to read the annotations as well?


Consider this method definition:-



public class ABC {
public static @MyAnnotation @AnotherAnnotation String main(String args[]) {

return null;
}


So my question is :- Can we read the annotations defined in the return type String??


The annotations are as follows:-


MyAnnotation.java



@Target(value = ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {

public String[] author() default {"Its me","Its me"};



}


AnotherAnnotation.java



@Target(value = ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface AnotherAnnotation {

}





Aucun commentaire:

Enregistrer un commentaire