Online Java Compiler By
JavaTpoint.com
import java.lang.annotation.*; import java.lang.reflect.AnnotatedType; import java.lang.reflect.Method; import java.util.Arrays; public class ReflectMethodgetAnnotatedReturnTypeExample2 { @Target({ ElementType.TYPE_USE }) @Retention(RetentionPolicy.RUNTIME) private @interface customAnnotatedType { } public @customAnnotatedType String getAddress() { return null; } // main method public static void main(String[] args) { try { Class classobj = ReflectMethodgetAnnotatedReturnTypeExample2.class; Method getAddressMethod = null; Method[] methods = classobj.getMethods(); for (Method mthd : methods) { if (mthd.getName().equals("getAddress")) getAddressMethod = mthd; } AnnotatedType annotatedType = getAddressMethod .getAnnotatedReturnType(); System.out.println("Annotations: " + Arrays.toString(annotatedType.getAnnotations())); } catch (Exception e) { e.printStackTrace(); } } }
Output