• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17 
18 package java.lang.reflect;
19 
20 import java.lang.annotation.Annotation;
21 
22 /**
23  * This interface provides reflective access to annotation information.
24  *
25  * @since 1.5
26  */
27 public interface AnnotatedElement {
28 
29     /**
30      * Returns, for this element, the annotation with the specified type, or
31      * {@code null} if no annotation with the specified type is present
32      * (including inherited annotations).
33      *
34      * @param annotationType
35      *            the type of the annotation to search for
36      * @return the annotation with the specified type or {@code null}
37      * @throws NullPointerException
38      *             if {@code annotationType} is {@code null}
39      */
getAnnotation(Class<T> annotationType)40     <T extends Annotation> T getAnnotation(Class<T> annotationType);
41 
42     /**
43      * Returns, for this element, an array containing all annotations (including
44      * inherited annotations). If there are no annotations present, this method
45      * returns a zero length array.
46      *
47      * @return an array of all annotations for this element
48      */
getAnnotations()49     Annotation[] getAnnotations();
50 
51     /**
52      * Returns, for this element, all annotations that are explicitly declared
53      * (not inherited). If there are no declared annotations present, this
54      * method returns a zero length array.
55      *
56      * @return an array of annotations declared for this element
57      */
getDeclaredAnnotations()58     Annotation[] getDeclaredAnnotations();
59 
60     /**
61      * Indicates whether or not this element has an annotation with the
62      * specified annotation type (including inherited annotations).
63      *
64      * @param annotationType
65      *            the type of the annotation to search for
66      * @return {@code true} if the annotation exists, {@code false} otherwise
67      * @throws NullPointerException
68      *             if {@code annotationType} is {@code null}
69      */
isAnnotationPresent(Class<? extends Annotation> annotationType)70     boolean isAnnotationPresent(Class<? extends Annotation> annotationType);
71 }
72