Java Reflection Method Parameter getMethodParametersType(Class clazz, String methodName)

Here you can find the source of getMethodParametersType(Class clazz, String methodName)

Description

Get the method parameter type array

License

Apache License

Parameter

Parameter Description
clazz whose method required
methodName whose parameter required

Exception

Parameter Description
NoSuchMethodException an exception

Return

Array of parameter type

Declaration

public static Class<?>[] getMethodParametersType(Class<?> clazz, String methodName)
        throws NoSuchMethodException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;

public class Main {
    /**/*from   w  ww  . ja v a 2 s  .c o m*/
     * Get the method parameter type array
     * @param clazz whose method required
     * @param methodName whose parameter required
     * @return Array of parameter type 
     * @throws NoSuchMethodException
     */
    public static Class<?>[] getMethodParametersType(Class<?> clazz, String methodName)
            throws NoSuchMethodException {
        for (Method method : clazz.getMethods()) {
            if (method.getName().equals(methodName)) {
                return method.getParameterTypes();
            }
        }
        throw new NoSuchMethodException(
                "No such method is paresent in " + clazz.getName() + " of name " + methodName);
    }
}

Related

  1. getMethodHandle(final Lookup lookup, final Class receiver, final String methodName, final Class... parameterTypes)
  2. getMethodName(Method method, Class[] parameterClasses, String rightCode)
  3. getMethodParameterAnnotations(Method method, int index, Class annotationClass)
  4. getMethodParameterIndexes(final Method m)
  5. getMethodParameters(final Method method, final Map generics)
  6. getMethodParameterTypes(final Method method)
  7. getMethodQuietly(Class clazz, String methodName, Class... parameterTypes)
  8. getMethodRecursive(final Class clazz, final String methodName, final Class... parameterTypes)
  9. getMethodsWith(Class c, Class... parameters)