Java Reflection Method Name getMethod(Class clazz, String name, Class... args)

Here you can find the source of getMethod(Class clazz, String name, Class... args)

Description

get Method

License

Open Source License

Declaration

public static Method getMethod(Class<?> clazz, String name, Class<?>... args) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Method;

public class Main {
    public static Method getMethod(Class<?> clazz, String name, Class<?>... args) {
        for (Method m : clazz.getMethods())
            if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args, m.getParameterTypes()))) {
                m.setAccessible(true);/*  w  ww.  j a v  a  2s . c  o  m*/
                return m;
            }
        return null;
    }

    public static boolean ClassListEqual(Class<?>[] l1, Class<?>[] l2) {
        boolean equal = true;
        if (l1.length != l2.length)
            return false;
        for (int i = 0; i < l1.length; i++)
            if (l1[i] != l2[i]) {
                equal = false;
                break;
            }
        return equal;
    }
}

Related

  1. getMethod(Class clazz, String name)
  2. getMethod(Class clazz, String name)
  3. getMethod(Class clazz, String name)
  4. getMethod(Class clazz, String name, boolean declared, Class... args)
  5. getMethod(Class clazz, String name, Class... args)
  6. getMethod(Class clazz, String name, Class... params)
  7. getMethod(Class clazz, String name, int paramlength)
  8. getMethod(Class clazz, String... names)
  9. getMethod(Class cls, String name)