113 * {@code getAnnotation(annotationClass) != null} 114 * 115 * <p>The body of the default method is specified to be the code 116 * above. 117 * 118 * @param annotationClass the Class object corresponding to the 119 * annotation type 120 * @return true if an annotation for the specified annotation 121 * type is present on this element, else false 122 * @throws NullPointerException if the given annotation class is null 123 * @since 1.5 124 */ 125 default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) { 126 return getAnnotation(annotationClass) != null; 127 } 128 129 /** 130 * Returns this element's annotation for the specified type if 131 * such an annotation is present, else null. 132 * 133 * @param annotationClass the Class object corresponding to the 134 * annotation type 135 * @return this element's annotation for the specified annotation type if 136 * present on this element, else null 137 * @throws NullPointerException if the given annotation class is null 138 * @since 1.5 139 */ 140 <T extends Annotation> T getAnnotation(Class<T> annotationClass); 141 142 /** 143 * Returns annotations that are <em>present</em> on this element. 144 * 145 * If there are no annotations <em>present</em> on this element, the return 146 * value is an array of length 0. 147 * 148 * The difference between this method and {@link #getAnnotation(Class)} 149 * is that this method detects if its argument is a <em>repeatable 150 * annotation type</em> (JLS 9.6), and if so, attempts to find one or 151 * more annotations of that type by "looking through" a container 152 * annotation. 153 * 154 * The caller of this method is free to modify the returned array; it will 155 * have no effect on the arrays returned to other callers. 156 * 157 * @param annotationClass the Class object corresponding to the 158 * annotation type 159 * @return all this element's annotations for the specified annotation type if 160 * present on this element, else an array of length zero 161 * @throws NullPointerException if the given annotation class is null 162 * @since 1.8 163 */ 164 <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass); 165 166 /** 167 * Returns annotations that are <em>present</em> on this element. 168 * 169 * If there are no annotations <em>present</em> on this element, the return 170 * value is an array of length 0. 171 * 172 * The caller of this method is free to modify the returned array; it will 173 * have no effect on the arrays returned to other callers. 174 * 175 * @return annotations present on this element 176 * @since 1.5 177 */ 178 Annotation[] getAnnotations(); 179 180 /** 181 * Returns this element's annotation for the specified type if 182 * such an annotation is present, else null. 183 * 184 * This method ignores inherited annotations. (Returns null if no 185 * annotations are directly present on this element.) 186 * 187 * @param annotationClass the Class object corresponding to the 188 * annotation type 189 * @return this element's annotation for the specified annotation type if 190 * present on this element, else null 191 * @throws NullPointerException if the given annotation class is null 192 * @since 1.8 193 */ 194 <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass); 195 196 /** 197 * Returns annotations that are <em>directly present</em> on this element. 198 * This method ignores inherited annotations. 199 * 200 * If there are no annotations <em>directly present</em> on this element, 201 * the return value is an array of length 0. 202 * 203 * The difference between this method and {@link 204 * #getDeclaredAnnotation(Class)} is that this method detects if its 205 * argument is a <em>repeatable annotation type</em> (JLS 9.6), and if so, 206 * attempts to find one or more annotations of that type by "looking 207 * through" a container annotation. 208 * 209 * The caller of this method is free to modify the returned array; it will 210 * have no effect on the arrays returned to other callers. 211 * 212 * @param annotationClass the Class object corresponding to the 213 * annotation type 214 * @return all this element's annotations for the specified annotation type if 215 * present on this element, else an array of length zero 216 * @throws NullPointerException if the given annotation class is null 217 * @since 1.8 218 */ 219 <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass); 220 221 /** 222 * Returns annotations that are <em>directly present</em> on this element. 223 * This method ignores inherited annotations. 224 * 225 * If there are no annotations <em>directly present</em> on this element, 226 * the return value is an array of length 0. 227 * 228 * The caller of this method is free to modify the returned array; it will 229 * have no effect on the arrays returned to other callers. 230 * 231 * @return annotations directly present on this element | 113 * {@code getAnnotation(annotationClass) != null} 114 * 115 * <p>The body of the default method is specified to be the code 116 * above. 117 * 118 * @param annotationClass the Class object corresponding to the 119 * annotation type 120 * @return true if an annotation for the specified annotation 121 * type is present on this element, else false 122 * @throws NullPointerException if the given annotation class is null 123 * @since 1.5 124 */ 125 default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) { 126 return getAnnotation(annotationClass) != null; 127 } 128 129 /** 130 * Returns this element's annotation for the specified type if 131 * such an annotation is present, else null. 132 * 133 * @param <T> the type of the annotation to query for and return if present 134 * @param annotationClass the Class object corresponding to the 135 * annotation type 136 * @return this element's annotation for the specified annotation type if 137 * present on this element, else null 138 * @throws NullPointerException if the given annotation class is null 139 * @since 1.5 140 */ 141 <T extends Annotation> T getAnnotation(Class<T> annotationClass); 142 143 /** 144 * Returns annotations that are <em>present</em> on this element. 145 * 146 * If there are no annotations <em>present</em> on this element, the return 147 * value is an array of length 0. 148 * 149 * The difference between this method and {@link #getAnnotation(Class)} 150 * is that this method detects if its argument is a <em>repeatable 151 * annotation type</em> (JLS 9.6), and if so, attempts to find one or 152 * more annotations of that type by "looking through" a container 153 * annotation. 154 * 155 * The caller of this method is free to modify the returned array; it will 156 * have no effect on the arrays returned to other callers. 157 * 158 * @param <T> the type of the annotation to query for and return if present 159 * @param annotationClass the Class object corresponding to the 160 * annotation type 161 * @return all this element's annotations for the specified annotation type if 162 * present on this element, else an array of length zero 163 * @throws NullPointerException if the given annotation class is null 164 * @since 1.8 165 */ 166 <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass); 167 168 /** 169 * Returns annotations that are <em>present</em> on this element. 170 * 171 * If there are no annotations <em>present</em> on this element, the return 172 * value is an array of length 0. 173 * 174 * The caller of this method is free to modify the returned array; it will 175 * have no effect on the arrays returned to other callers. 176 * 177 * @return annotations present on this element 178 * @since 1.5 179 */ 180 Annotation[] getAnnotations(); 181 182 /** 183 * Returns this element's annotation for the specified type if 184 * such an annotation is present, else null. 185 * 186 * This method ignores inherited annotations. (Returns null if no 187 * annotations are directly present on this element.) 188 * 189 * @param <T> the type of the annotation to query for and return if present 190 * @param annotationClass the Class object corresponding to the 191 * annotation type 192 * @return this element's annotation for the specified annotation type if 193 * present on this element, else null 194 * @throws NullPointerException if the given annotation class is null 195 * @since 1.8 196 */ 197 <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass); 198 199 /** 200 * Returns annotations that are <em>directly present</em> on this element. 201 * This method ignores inherited annotations. 202 * 203 * If there are no annotations <em>directly present</em> on this element, 204 * the return value is an array of length 0. 205 * 206 * The difference between this method and {@link 207 * #getDeclaredAnnotation(Class)} is that this method detects if its 208 * argument is a <em>repeatable annotation type</em> (JLS 9.6), and if so, 209 * attempts to find one or more annotations of that type by "looking 210 * through" a container annotation. 211 * 212 * The caller of this method is free to modify the returned array; it will 213 * have no effect on the arrays returned to other callers. 214 * 215 * @param <T> the type of the annotation to query for and return 216 * if directly present 217 * @param annotationClass the Class object corresponding to the 218 * annotation type 219 * @return all this element's annotations for the specified annotation type if 220 * present on this element, else an array of length zero 221 * @throws NullPointerException if the given annotation class is null 222 * @since 1.8 223 */ 224 <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass); 225 226 /** 227 * Returns annotations that are <em>directly present</em> on this element. 228 * This method ignores inherited annotations. 229 * 230 * If there are no annotations <em>directly present</em> on this element, 231 * the return value is an array of length 0. 232 * 233 * The caller of this method is free to modify the returned array; it will 234 * have no effect on the arrays returned to other callers. 235 * 236 * @return annotations directly present on this element |