Java Reflection Method Invoke invokeMethod(String methodName, Object gameCommand)

Here you can find the source of invokeMethod(String methodName, Object gameCommand)

Description

invoke Method

License

Open Source License

Declaration

public static Object invokeMethod(String methodName, Object gameCommand) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main {
    public static Object invokeMethod(String methodName, Object gameCommand) {
        Method method;//from ww  w.  ja v  a2 s  .c o m
        Object returnObj = null;
        try {
            method = gameCommand.getClass().getDeclaredMethod(methodName);
            method.setAccessible(true);
            returnObj = method.invoke(gameCommand);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return returnObj;
    }
}

Related

  1. invokeMethod(Object target, String name, Object[] args, Class[] argTypes)
  2. invokeMethod(Object target, String signature, Object... args)
  3. invokeMethod(Object target, String thisMethod, Object value)
  4. invokeMethod(Object theObject, String methodName, Object... parametersObject)
  5. invokeMethod(String className, String method, Class[] paramTypes, Object obj, Object[] args)
  6. invokeMethod(String name, Object target)
  7. invokeMethod2(Class cls, Object obj, String methodName, Object[] args)
  8. invokeMethodAndGet(Object object, String methodName, Object... args)
  9. invokeMethodAndGetRecursively(Object object, String methodName, Object... args)