日期:2014-05-20 浏览次数:20724 次
@Target({METHOD, CONSTRUCTOR, FIELD, PARAMETER}) @Retention(RUNTIME) public @interface W { String value() default "WANGNING"; }
public class Demo { @W() public void setMethod(){ } }
public class RunTests { public static void main(String[] args) throws Exception { for (Method m : Class.forName("homework.Demo").getMethods()) { if(m.isAnnotationPresent(W.class)){ System.out.println(m.getAnnotation(W.class)); System.out.println(m.getDefaultValue()); } } } }