java反射调用有参方法

Object obj = Class.forName("").newInstance();

public void invokeMethod(Object obj, String methodName, Object[] param)
			throws Exception {
		Class clazz = obj.getClass();
		Class[] classArgs = new Class[param.length];
		for (int i = 0; i < param.length; i++) {
			classArgs[i] = param[i].getClass();
		}
		Method method = clazz.getMethod(methodName, classArgs);
		method.invoke(obj, param);
	}

你可能感兴趣的:(java)