Java Utililty Methods Reflection Method Parameter

List of utility methods to do Reflection Method Parameter

Description

The list of methods to do Reflection Method Parameter are organized into topic(s).

Method

ListgetMethodGenericParameterTypes(Method method, int index)
get Method Generic Parameter Types
List<Class> results = new ArrayList<Class>();
Type[] genericParameterTypes = method.getGenericParameterTypes();
if (index >= genericParameterTypes.length || index < 0) {
    throw new IllegalArgumentException("index " + (index < 0 ? " must > 0 " : " over total arguments"));
Type genericParameterType = genericParameterTypes[index];
if (genericParameterType instanceof ParameterizedType) {
    ParameterizedType aType = (ParameterizedType) genericParameterType;
...
MethodHandlegetMethodHandle(final Lookup lookup, final Class receiver, final String methodName, final Class... parameterTypes)
get Method Handle
return unreflect(lookup, getMethod(receiver, methodName, parameterTypes));
StringgetMethodName(Method method, Class[] parameterClasses, String rightCode)
get Method Name
if (method.getParameterTypes().length > parameterClasses.length) {
    Class<?>[] types = method.getParameterTypes();
    StringBuilder buf = new StringBuilder(rightCode);
    for (int i = parameterClasses.length; i < types.length; i++) {
        if (buf.length() > 0) {
            buf.append(",");
        Class<?> type = types[i];
...
ListgetMethodParameterAnnotations(Method method, int index, Class annotationClass)
Get Annotation s of the provided class associated to the the provided method parameter.
Annotation[][] parametersAnnotations = method.getParameterAnnotations();
Annotation[] parameterAnnotations = parametersAnnotations[index];
List<A> foundAnnotations = new ArrayList<A>();
for (Annotation annotation : parameterAnnotations) {
    if (annotationClass.isInstance(annotation)) {
        foundAnnotations.add((A) annotation);
return foundAnnotations;
MapgetMethodParameterIndexes(final Method m)
Try to determine the names of the method parameters.
if ((GETPARAMETERS == null) || (m == null)) {
    return Collections.emptyMap();
Map<String, Integer> paramNames = new HashMap<String, Integer>();
try {
    Object[] params = (Object[]) GETPARAMETERS.invoke(m);
    if (params.length == 0) {
        return Collections.emptyMap();
...
List>getMethodParameters(final Method method, final Map generics)
Resolve generics in method parameters.
final List<Class<?>> params = new ArrayList<Class<?>>();
for (Type type : method.getGenericParameterTypes()) {
    params.add(resolveClass(type, generics));
return params;
Class[]getMethodParametersType(Class clazz, String methodName)
Get the method parameter type array
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);
Class[]getMethodParameterTypes(final Method method)
Get the list of parameter types for a given method.
return method.getParameterTypes();
MethodgetMethodQuietly(Class clazz, String methodName, Class... parameterTypes)
get Method Quietly
try {
    return clazz.getMethod(methodName, parameterTypes);
} catch (NoSuchMethodException ex) {
    return null;
MethodgetMethodRecursive(final Class clazz, final String methodName, final Class... parameterTypes)
get Method Recursive
final Method m = getMethod(clazz, methodName, parameterTypes);
if (m != null)
    return m;
final Class<?> superclazz = clazz.getSuperclass();
if (superclazz == null)
    return null;
return getMethodRecursive(superclazz, methodName, parameterTypes);