Here you can find the source of invokeMethod(String methodName, Object gameCommand)
public static Object invokeMethod(String methodName, Object gameCommand)
//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; } }