Java Reflection Method Get from Object getMethod(final Class clazz, final String methodName, final Class[] parTypes, final Object[] parameters)

Here you can find the source of getMethod(final Class clazz, final String methodName, final Class[] parTypes, final Object[] parameters)

Description

get Method

License

Open Source License

Declaration

private static Method getMethod(final Class<? extends Object> clazz, final String methodName,
            final Class<?>[] parTypes, final Object[] parameters) throws NoSuchMethodException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 SAP AG 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://from ww w . j a  v a  2  s  . c  o m
 *     SAP AG - initial API and implementation
 *******************************************************************************/

import java.lang.reflect.Method;

public class Main {
    private static Method getMethod(final Class<? extends Object> clazz, final String methodName,
            final Class<?>[] parTypes, final Object[] parameters) throws NoSuchMethodException {
        assert clazz != null && methodName != null && parTypes != null && parameters != null;

        try {
            return clazz.getDeclaredMethod(methodName, parTypes);
        } catch (NoSuchMethodException e) {
            final Class<?> superClass = clazz.getSuperclass();
            if (superClass != null) {
                return getMethod(superClass, methodName, parTypes, parameters);
            }
            throw e;
        }
    }
}

Related

  1. getMethod(Class cls, String method, Object[] params)
  2. getMethod(Class clz, String methodName, Object... params)
  3. getMethod(Class klass, String methodName, Object... params)
  4. getMethod(Class objectType, String methodName, Class... parameterTypes)
  5. getMethod(Class type, String name, Object[] args)
  6. getMethod(final Object object, final String methodName, final Class... parameterClass)
  7. getMethod(final Object object, final String methodName, final Object... arguments)
  8. getMethod(final Object object, final String methodName, final Object... arguments)
  9. getMethod(final Object object, String methodName, final Class[] argTypes)