Here you can find the source of invoke(Object host, String method, Object[] args)
public static Object invoke(Object host, String method, Object[] args) throws Exception
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; public class Main { public static Object invoke(Object host, String method, Object[] args) throws Exception { Class clz = host.getClass(); for (Method m : clz.getMethods()) { if (m.getName().equals(method) && m.getParameterCount() == args.length) { Class[] paramTypes = m.getParameterTypes(); for (int i = 0; i < paramTypes.length; ++i) args[i] = rectifyValue(paramTypes[i], args[i]); return m.invoke(host, args); }//www .j av a 2s . co m } return null; } public static Object rectifyValue(Class type, Object value) { if (type == byte.class || type == Byte.class) return new Byte(((Number) value).byteValue()); if (type == char.class || type == Character.class) return new Character(value.toString().charAt(0)); if (type == short.class || type == Short.class) return new Short(((Number) value).shortValue()); if (type == int.class || type == Integer.class) return new Integer(((Number) value).intValue()); if (type == long.class || type == Long.class) return new Long(((Number) value).longValue()); if (type == float.class || type == Float.class) return new Float(((Number) value).floatValue()); return value; } }