Here you can find the source of invokeMethod(Class clazz, String methodName, Object[] args)
public static Object invokeMethod(Class clazz, String methodName, Object[] args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 IBM Corporation 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:/* w w w. j a va 2 s. c om*/ * IBM Corporation - initial API and implementation *******************************************************************************/ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { public static Object invokeMethod(Class clazz, String methodName, Object[] args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException { return invokeMethod(clazz, null, methodName, args); } public static Object invokeMethod(Class clazz, Object target, String methodName, Object[] args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException { Class[] signature = new Class[args.length]; for (int i = 0; i < args.length; i++) { Class thisClass = args[i].getClass(); if (thisClass == Integer.class) signature[i] = int.class; else if (thisClass == Long.class) signature[i] = long.class; else if (thisClass == Byte.class) signature[i] = byte.class; else signature[i] = thisClass; } Method method = clazz.getMethod(methodName, signature); return method.invoke(target, args); } }