Java Reflection Method Name getMethodInternal(Class clazz, String methodName)

Here you can find the source of getMethodInternal(Class clazz, String methodName)

Description

Does the actual search for the method

License

Open Source License

Declaration

private static Method getMethodInternal(Class<?> clazz, String methodName) throws Exception 

Method Source Code

//package com.java2s;
/**//from  w w w. j a va2  s  .com
 * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
 * reserved. This program and the accompanying materials are made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal - Initial API and
 * implementation </copyright> $Id: FieldUtil.java,v 1.15 2008/06/02 07:15:29 mtaal Exp $
 */

import java.lang.reflect.Method;
import java.util.Hashtable;

public class Main {
    /** The hashtable caches clazz field name combinations */
    private static final Hashtable<String, Object> fieldMethodCache = new Hashtable<String, Object>();

    /** Does the actual search for the method */
    private static Method getMethodInternal(Class<?> clazz, String methodName) throws Exception {
        if (clazz == null) {
            return null;
        }

        final Method method = (Method) fieldMethodCache.get(clazz.getName() + "." + methodName);
        if (method != null) {
            return method;
        }
        final Method[] methods = clazz.getDeclaredMethods();
        for (Method element : methods) {
            if (element.getName().compareToIgnoreCase(methodName) == 0) {
                element.setAccessible(true);
                fieldMethodCache.put(clazz.getName() + "." + methodName, element);
                return element;
            }
        }

        return getMethodInternal(clazz.getSuperclass(), methodName);
    }
}

Related

  1. getMethodIfAvailable(Class clazz, String methodName, Class... paramTypes)
  2. getMethodIfAvailable(Class clazz, String methodName, Class... paramTypes)
  3. getMethodIfAvailable(Class clazz, String methodName, Class... paramTypes)
  4. getMethodIfAvailable(Class clazz, String methodName, Class... paramTypes)
  5. getMethodIncludingSuperClass(Class clazz, String methodName)
  6. getMethodName()
  7. getMethodName()
  8. getMethodName(final int depth)
  9. getMethodName(Method method)