Java Reflection Annotation getAnnotation(final Class annotationClass, final AnnotatedElement... elements)

Here you can find the source of getAnnotation(final Class annotationClass, final AnnotatedElement... elements)

Description

Returns the first element which has an annotation of the given type declared.

License

Open Source License

Declaration

public static <ANNOTATION extends Annotation> ANNOTATION getAnnotation(final Class<ANNOTATION> annotationClass,
        final AnnotatedElement... elements) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010-2015 BSI Business Systems Integration AG.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/* w ww. jav a2  s. c o  m*/
 *     BSI Business Systems Integration AG - initial API and implementation
 ******************************************************************************/

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;

public class Main {
    /**
     * Returns the first element which has an annotation of the given type declared.
     */
    public static <ANNOTATION extends Annotation> ANNOTATION getAnnotation(final Class<ANNOTATION> annotationClass,
            final AnnotatedElement... elements) {
        for (final AnnotatedElement element : elements) {
            final ANNOTATION annotation = element.getAnnotation(annotationClass);
            if (annotation != null) {
                return annotation;
            }
        }
        return null;
    }
}

Related

  1. getAnnotation(final AnnotatedElement annotatedElement, final Class annotationClass)
  2. getAnnotation(final Class c, final Class annClass)
  3. getAnnotation(final Class annotatedClass, final Class annotationClass)
  4. getAnnotation(final Class type, final Class annotation)
  5. getAnnotation(final Class reference, final AccessibleObject obj)
  6. getAnnotation(final Member member, final Class annotation)
  7. getAnnotation(final Method method, final Class annotationClass)
  8. getAnnotation(final Object obj, final Class annoType)
  9. getAnnotation(final Object object, final Class annotationClass)