问个反射的问题,
首先,我定义了一个注解名为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());
}
}
}
}
我的问题是,m.getDefaultValue()为什么是null,我的注解里有缺省值啊