12.4.4 AnnotatedElement接口
前面例子中使用的getAnnotation()和getAnnotations()方法是由AnnotatedElement接口定义的,该接口在java.lang.reflect包中定义。这个接口支持注解反射,并且类Method、Field、Constructor、Class以及Package也都实现了该接口。
Annotation[ ] getDeclaredAnnotations( )
Annotation[ ] getDeclaredAnnotations( ) 上述方法返回调用对象中存在的所有非继承注解。第二个方法是isAnnotationPresent(),该方法的一般形式如下所示:
boolean isAnnotationPresent(Class<? extends Annotation> annoType)
如果annoType指定的注解与调用对象相关联,那么该方法返回true,否则返回false。