复制代码 代码如下:
public static Class[] getMethodParamTypes(Object classInstance,
String methodName) throws ClassNotFoundException{
Class[] paramTypes = null;
Method[] methods = classInstance.getClass().getMethods();//全部方法
for (int i = 0; i< methods.length; i++) {
if(methodName.equals(methods[i].getName())){//和传入方法名匹配
Class[] params = methods[i].getParameterTypes();
paramTypes = new Class[ params.length] ;
for (int j = 0; j < params.length; j++) {
paramTypes[j] = Class.forName(params[j].getName());
}
break;
}
}
return paramTypes;
}
//取得方法测试(Test类大家还是任意写吧,这里不列举了)
Method m = Test.class.newInstance().getClass().getDeclaredMethod("方法名称", getMethodParamTypes(Test.class.newInstance(),"方法名称"));



