我正在尝试使用 Java 注释,但似乎无法让我的代码识别出存在。我究竟做错了什么?
import java.lang.reflect.*;
import java.lang.annotation.*;
@interface MyAnnotation{}
public class FooTest
{
@MyAnnotation
public void doFoo()
{
}
public static void main(String[] args) throws Exception
{
Method method = FooTest.class.getMethod( "doFoo" );
Annotation[] annotations = method.getAnnotations();
for( Annotation annotation : method.getAnnotations() )
System.out.println( "Annotation: " + annotation );
}
}