Java Reflection Method Get from Object getMethodObject(Class type, Class clazz, String method, Class[] args, Object object, Object[] objects)

Here you can find the source of getMethodObject(Class type, Class clazz, String method, Class[] args, Object object, Object[] objects)

Description

get Method Object

License

Open Source License

Declaration

public static <T> Object getMethodObject(Class<? extends T> type, Class<?> clazz, String method,
            Class<?>[] args, Object object, Object[] objects) 

Method Source Code

//package com.java2s;
/**/*  www  .  ja  v  a2  s  .co  m*/
 * 
 * This software is part of the MaterialAPI
 * 
 * This api allows plugin developers to create on a easy way custom
 * items with a custom id and recipes depending on them.
 * 
 * MaterialAPI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or 
 * any later version.
 *  
 * MaterialAPI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MaterialAPI. If not, see <http://www.gnu.org/licenses/>.
 * 
 */

import java.lang.reflect.Method;

public class Main {
    public static <T> Object getMethodObject(Class<? extends T> type, Class<?> clazz, String method,
            Class<?>[] args, Object object, Object[] objects) {
        Object o = getMethodObject(clazz, method, args, object, objects);
        return o == null ? null : type.cast(o);
    }

    public static Object getMethodObject(Class<?> clazz, String method, Class<?>[] args, Object object,
            Object[] objects) {
        try {
            Method m = clazz.getDeclaredMethod(method, args);
            m.setAccessible(true);
            return m.invoke(object, objects);
        } catch (Exception ex) {
        }

        return null;
    }

    public static Object getMethodObject(Class<?> clazz, String method, Object object) {
        return getMethodObject(clazz, method, new Class[] {}, object, new Object[] {});
    }
}

Related

  1. getMethodInstace(Class c, Object inst, String name, Class[] types, boolean access)
  2. getMethodName(AccessibleObject method)
  3. getMethodNamed(String methodName, Object holder)
  4. getMethodNames(Object obj, boolean hasParent)
  5. getMethodNames(Object obj, boolean includeInheritedMethods)
  6. getMethodObject(Object object, String method, Object[] parametre)
  7. getMethodResult(final Object element, final String methodName)
  8. getMethodReturn(String className, String methodName, Class[] params, Object[] args, boolean isStatic)
  9. getMethodReturnTypeGeneric(Object source, Method method)