Here you can find the source of getMethodCountForName(Class> clazz, String methodName)
Parameter | Description |
---|---|
clazz | the clazz to check |
methodName | the name of the method |
public static int getMethodCountForName(Class<?> clazz, String methodName)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; public class Main { /**/*w ww . j a v a 2s . c o m*/ * Return the number of methods with a given name (with any argument types), * for the given class and/or its superclasses. Includes non-public methods. * @param clazz the clazz to check * @param methodName the name of the method * @return the number of methods with the given name */ public static int getMethodCountForName(Class<?> clazz, String methodName) { int count = 0; Method[] declaredMethods = clazz.getDeclaredMethods(); for (Method method : declaredMethods) { if (methodName.equals(method.getName())) { count++; } } Class<?>[] ifcs = clazz.getInterfaces(); for (Class<?> ifc : ifcs) { count += getMethodCountForName(ifc, methodName); } if (clazz.getSuperclass() != null) { count += getMethodCountForName(clazz.getSuperclass(), methodName); } return count; } }