Java Reflection Annotation Find findAnnotation(Set annotations, Class annotationClass)

Here you can find the source of findAnnotation(Set annotations, Class annotationClass)

Description

find Annotation

License

Apache License

Declaration

public static Annotation findAnnotation(Set<? extends Annotation> annotations,
            Class<? extends Annotation> annotationClass) 

Method Source Code


//package com.java2s;
/*//from  w  ww  .  j  a v a 2 s. com
 * Copyright 2014 Square, Inc.
 * Copyright 2016 Serj Lotutovici
 *
 * 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;
import java.util.Set;

public class Main {
    public static Annotation findAnnotation(Set<? extends Annotation> annotations,
            Class<? extends Annotation> annotationClass) {
        if (annotations.isEmpty())
            return null; // Save an iterator in the common case.
        for (Annotation annotation : annotations) {
            if (annotation.annotationType() == annotationClass) {
                return annotation;
            }
        }
        return null;
    }
}

Related

  1. findAnnotation(final Class targetAnnotation, final Class annotatedType)
  2. findAnnotation(final Class annotationClass, final Class beanClass, final Field field)
  3. findAnnotation(final Set annotations, final Class annotationType)
  4. findAnnotation(Method method, Class annotationType)
  5. findAnnotation(Method method, Class type)
  6. findAnnotationClass( Class c, Class base)
  7. findAnnotationDeclaringClass(Class annotationType, Class clazz)
  8. findAnnotationDeclaringClass(Class annotationType, Class classToFind)
  9. findAnnotationDeclaringClass(Class annotationType, Class clazz)