Here you can find the source of getAnnotation(final Class
public static <ANNOTATION extends Annotation> ANNOTATION getAnnotation(final Class<ANNOTATION> annotationClass, final AnnotatedElement... elements)
//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; } }