Annotation 求助,为什么getAnnotations()没有结果?
我用getAnnotations()方法得到的数组Annotation[] anns,为什么数组长度为0,没有得到相应的annotation注释?
import java.lang.annotation.Annotation;
public class AnnotationTest {
	public static void main(String[] args){	
		try{
		    Annotation[]anns=Class.forName("Apple").getMethod("info").getAnnotations();
		    System.out.println(anns.length);
		    for(Annotation ann:anns){
		    	System.out.println(ann);
		    }
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
}
@interface MyTag{
	String name() default "ddd";
	int age();
}
class Fruit{
	public void info(){
		
		System.out.println("Fruit info method.");
	}
}
class Apple extends Fruit{
	@MyTag(age=34)
	@Override
	public void info(){
		
	}
	@Deprecated
	public void foo(){
		
	}
}
------解决方案--------------------需要设置@Retention(RetentionPolicy.RUNTIME)这个表示运行期注解,这样在反射的时候才能取到