映射

Class clazz = Class.forName("com.npsel.report.action.CommonMethod");

// 无参数

Method method = clazz.getDeclaredMethod("get"+tdRecord.toUpperCase());
tdRecord = (String) method.invoke(clazz.newInstance());

// 有参数

Method method = clazz.getDeclaredMethod("say" + methodStr, new Class[]{String.class,int.class});
method.invoke(clazz.newInstance(), new Object[]{name,age});

 
// 构造函数

Constructor constructor = clazz.getConstructor(Except.class);
EdiServiceDao ediServiceDao = (EdiServiceDao) constructor.newInstance(except);
ediServiceDao.getSBufferOutput(request, response);

原文地址:https://www.cnblogs.com/MissRabbit/p/6935097.html