日期:2014-05-20 浏览次数:20768 次
import java.lang.reflect.*; public class Test { public static void main(String[] args) { Class c=null; try { c=Class.forName("day16.Student"); Method[] m=c.getDeclaredMethods(); for(int i=0;i<m.length;i++){ author ann=m[i].getAnnotation(Class.forName("author")); System.out.println(m[i].getName()+":"+ann.value()+":"+ann.date()); } } catch (ClassNotFoundException e) { e.printStackTrace(); } } }
import java.lang.annotation.*; @Documented @Inherited @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD,ElementType.TYPE}) public @interface author { public String value(); public String date(); }