@Retention(RetentionPolicy.RUNTIME) @interface MyAnnotation { int value(); int defaultValue() default 100; } public class CustomAnnoat { @MyAnnotation(101) public static void myMethod() { } public static void main(String[] arg) { try { CustomAnnoat ob = new CustomAnnoat (); Method m = ob.getClass( ).getMethod("myMethod"); Annotation[] annos = m.getAnnotations(); System.out.println("All annotations for myMeth:"); for(Annotation a : annos) System.out.println(a); } catch (Exception exc) { } } }
No comments:
Post a Comment