Java Reflection Annotation getAnnotation(Member m, Class annotationClass)

Here you can find the source of getAnnotation(Member m, Class annotationClass)

Description

get Annotation

License

Open Source License

Declaration

private static <T extends Annotation> T getAnnotation(Member m,
            Class<T> annotationClass) 

Method Source Code

//package com.java2s;
/*/*from   w ww  . j  a  v a 2 s.c o  m*/
 * Quasar: lightweight threads and actors for the JVM.
 * Copyright (c) 2013-2015, Parallel Universe Software Co. All rights reserved.
 * 
 * This program and the accompanying materials are dual-licensed under
 * either the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation
 *  
 *   or (per the licensee's choosing)
 *  
 * under the terms of the GNU Lesser General Public License version 3.0
 * as published by the Free Software Foundation.
 */

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Member;
import java.lang.reflect.Method;

public class Main {
    private static <T extends Annotation> T getAnnotation(Member m,
            Class<T> annotationClass) {
        if (m == null || annotationClass == null)
            return null;

        if (m instanceof Constructor)
            return ((Constructor<?>) m).getAnnotation(annotationClass);
        else
            return ((Method) m).getAnnotation(annotationClass);
    }
}

Related

  1. getAnnotation(final Class annotationClass, final AnnotatedElement... elements)
  2. getAnnotation(final Member member, final Class annotation)
  3. getAnnotation(final Method method, final Class annotationClass)
  4. getAnnotation(final Object obj, final Class annoType)
  5. getAnnotation(final Object object, final Class annotationClass)
  6. getAnnotation(Method m, Class annotationClass)
  7. getAnnotation(Method method, Class annotationType)
  8. getAnnotation(Method method, Class annotationClass)
  9. getAnnotation(Method method, Class annotationClass)