Java Reflection Method Parameter getMethod(final Class aClass, final String methodName, Class[] parameterTypes)

Here you can find the source of getMethod(final Class aClass, final String methodName, Class[] parameterTypes)

Description

Warning : each call of this method should be tested with a JUnit test, in order to know when the API has changed

License

Open Source License

Parameter

Parameter Description
aClass a class
methodName the name of the method to find
parameterTypes an array owning the type of the parameters of the called method

Exception

Parameter Description
NoSuchMethodException an exception
SecurityException an exception

Return

the wanted method

Declaration

public static Method getMethod(final Class<?> aClass, final String methodName, Class<?>[] parameterTypes)
        throws SecurityException, NoSuchMethodException 

Method Source Code

//package com.java2s;
/*****************************************************************************
 * Copyright (c) 2012 CEA LIST./*  w  ww . j  a  v a2s  .  c o  m*/
 * 
 * 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:
 *  Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
 *****************************************************************************/

import java.lang.reflect.Method;

public class Main {
    /**
     * Warning : each call of this method should be tested with a JUnit test, in order to know
     * when the API has changed
     * 
     * @param aClass
     *        a class
     * @param methodName
     *        the name of the method to find
     * @param parameterTypes
     *        an array owning the type of the parameters of the called method
     * @return
     *         the wanted method
     * @throws NoSuchMethodException
     * @throws SecurityException
     */
    public static Method getMethod(final Class<?> aClass, final String methodName, Class<?>[] parameterTypes)
            throws SecurityException, NoSuchMethodException {
        Method m = null;
        m = aClass.getDeclaredMethod(methodName, parameterTypes);
        m.setAccessible(true);
        return m;
    }
}

Related

  1. getMethod(Class type, String name, Class... parameterTypes)
  2. getMethod(Class type, String name, Class... parameterTypes)
  3. getMethod(Class clazz, String methodName, Class[] parameterTypes)
  4. getMethod(final Class clazz, final String name, final Class... parameterTypes)
  5. getMethod(final Class javaClass, final String methodName, final Class[] methodParameterTypes, final boolean shouldSetAccessible)
  6. getMethod(final Class clazz, final String methodName, final Class... parameterTypes)
  7. getMethod(final Class clazz, final String name, final Class... parametertypes)
  8. getMethod(final Class clazz, final String name, final Class... parameterTypes)
  9. getMethod(final Class target, final String name, final Class... parameters)