Here you can find the source of getAnnotation(Class> annotationClass, Annotation[] annotations)
annotationClass
in the array of annotations.
Parameter | Description |
---|---|
annotationClass | type of the annotation to be searched for. |
annotations | array of annotation instances where the search is performed |
public static Annotation getAnnotation(Class<?> annotationClass, Annotation[] annotations)
//package com.java2s; /******************************************************************************* * Copyright 2012 Charles University in Prague * /* w w w . j a va 2 s .c o m*/ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ import java.lang.annotation.Annotation; public class Main { /** * Searches for annotation instance of the type specified by * <code>annotationClass</code> in the array of annotations. * * @param annotationClass * type of the annotation to be searched for. * @param annotations * array of annotation instances where the search is performed * @return found annotation instance or null if the search fails */ public static Annotation getAnnotation(Class<?> annotationClass, Annotation[] annotations) { for (Annotation a : annotations) { if (annotationClass.isInstance(a)) { return a; } } return null; } }