第五十五道Java小问题
import java.lang.annotation.ElementType;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;import java.lang.reflect.Method;@Target(ElementType.METHOD)@Retention(RetentionPolicy.RUNTIME)@interface TestAnnotation { public int id() default 5; public String description();}class Anno { @TestAnnotation(id = 6, description = "G") public void g() { } @TestAnnotation(id = 7, description = "I") protected void i() { } @TestAnnotation(id = 8, description = "F") void f() { } @TestAnnotation(id = 9, description = "H") private void h() { }}public class Test { public static void main(String[] args) { Method[] methods = Anno.class.getMethods(); for (Method m : methods) { TestAnnotation a = m.getAnnotation(TestAnnotation.class); // System.out.print(m.getName()); if (a != null) System.out.print(a.id()); } }}
?
?
请问以上程序的输出是: