Java Reflection Method Annotation getMethodName(final Class annoType, final Class klazType)

Here you can find the source of getMethodName(final Class annoType, final Class klazType)

Description

get Method Name

License

BSD License

Declaration

public static String getMethodName(final Class<? extends Annotation> annoType, final Class<?> klazType) 

Method Source Code

//package com.java2s;
/**/*from  w  ww  . j a v  a  2 s  .  c o m*/
 * Copyright (C) 2010-2012 Andrei Pozolotin <Andrei.Pozolotin@gmail.com>
 *
 * All rights reserved. Licensed under the OSI BSD License.
 *
 * http://www.opensource.org/licenses/bsd-license.php
 */

import java.lang.annotation.Annotation;

import java.lang.reflect.Method;

public class Main {
    public static String getMethodName(final Class<? extends Annotation> annoType, final Class<?> klazType) {

        final Method[] methodArray = klazType.getDeclaredMethods();

        for (final Method method : methodArray) {

            final Annotation anno = method.getAnnotation(annoType);

            if (anno != null) {
                return method.getName();
            }

        }

        return null;

    }
}

Related

  1. getMethodAnnotations(Method m)
  2. getMethodByAnnotation(Class cls, Class annotationClass)
  3. getMethodContainsAnnotations(Class target, Class annotation)
  4. getMethodInClassWithAnnotation(Class cls, Class annotationClass, int... modifiers)
  5. getMethodLevelAnnotations(Class clazz, Class annotation)
  6. getMethodOrClassLevelAnnotation(Class annotationClass, Method method, Class clazz)
  7. getMethods(Annotation anno)
  8. getMethods(Class clazz, Class annotation)
  9. getMethods(final Class clazz, final Class annotation)