Online Java Compiler By
JavaTpoint.com
//import statement import java.lang.annotation.*; //import annotation class of lang package import java.lang.reflect.Method; //import Method class of reflect package import java.util.Arrays; public class ReflectMethodgetParameterAnnotationsExample1 { public void Display(@DisplayConf Object config, @Deprecated @INDEX int n) {} public static void main(String... args) throws NoSuchMethodException { Method mthd = ReflectMethodgetParameterAnnotationsExample1.class.getDeclaredMethod("Display",Object.class, int.class); Annotation[][] prm = mthd.getParameterAnnotations(); System.out.println(Arrays.deepToString(prm)); for (Annotation[] an : prm) { for (Annotation ann : an) { System.out.println(ann); //print statement } } } @Target({ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) //retention policy private @interface INDEX {} @Target({ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) private @interface DisplayConf{} }
Output