Online Java Compiler By
JavaTpoint.com
//import statement import java.io.File; import java.lang.reflect.AnnotatedType; import java.lang.reflect.Method; import java.util.Arrays; public class ReflectMethodgetAnnotatedReturnTypeExample1 { public File get() {return null;} public static void main(String... args) throws NoSuchMethodException { Method mthd = ReflectMethodgetAnnotatedReturnTypeExample1.class.getDeclaredMethod("get"); AnnotatedType annotatedReturnType = mthd.getAnnotatedReturnType(); printAnnotatedType(annotatedReturnType); } private static void printAnnotatedType(AnnotatedType annotatedType) { System.out.println("Type: " + annotatedType.getType().getTypeName()); System.out.println("Annotations: " + Arrays.toString(annotatedType.getAnnotations())); } }
Output