ITeye博客

java反射调用有参方法

shaq34 · 2009-08-01 11:14 · Markdown


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);
	}


评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。