问一个反射的问题
问个反射的问题,
首先,我定义了一个注解名为W
@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()); } } }}