Here you can find the source of invokeMethod(Object target, String methodName, Object[] arguments)
public static Object invokeMethod(Object target, String methodName, Object[] arguments) throws InvocationTargetException, IllegalAccessException
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); you may not import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { public static Object invokeMethod(Object target, String methodName, Object[] arguments) throws InvocationTargetException, IllegalAccessException { Class targetClass = target.getClass(); Class[] argumentTypes = new Class[arguments.length]; for (int i = 0; i < argumentTypes.length; i++) { argumentTypes[i] = arguments[i].getClass(); }/*from www .j a v a 2 s . co m*/ try { Method method = targetClass.getMethod(methodName, argumentTypes); return method.invoke(target, arguments); } catch (SecurityException e) { } catch (NoSuchMethodException e) { } return null; } }