Mega Code Archive

 
Categories / Java / Reflection
 

Find method 2

import java.lang.reflect.Method; import java.util.HashSet; public abstract class ClassUtils {     static     public Method[] findMethods(Class<?> type, String methodName) {     if (type == null || methodName == null || methodName.length() == 0) {       return null;     }       try {           Method[] methods = type.getMethods();           HashSet<Method> findMethods = new HashSet<Method>();           for (Method method : methods) {               if (method.getName().equals(methodName)) {                   findMethods.add(method);               }           }           if (findMethods.size() > 0) {             return findMethods.toArray(new Method[findMethods.size()]);           }       } catch (Exception e) {       }       return null;   } }