Mega Code Archive

 
Categories / Java / Reflection
 

Find Declared Methods

import java.lang.reflect.Method; import java.util.HashSet; public abstract class ClassUtils {   static public Method[] findDeclaredMethods(Class<?> type, String methodName) {     if (type == null || methodName == null || methodName.length() == 0) {       return null;     }     try {       Method[] methods = type.getDeclaredMethods();       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;   } }