简单的通过配置文件加反射的方法执行某方法
public static void main(String[] args){
/**
* eg:txt配置文件class.txt或properties的配置文件
* className=xxx
* methodName=xxx
*/
Properties prop = new Properties();
FileRead fr = new FileRead("MyProject\\class.txt");
prop.load(fr);
fr.close();
String className = prop.getProperty("className");
String methodName = prop.getProperty("methodName");
//通过反射来使用
Class<?> c = Class.forName(className);
Constructor<?> con = c.getConstructor();
Object obj = con.newInstance();
Method m = c.getMethod(methodName);
m.invoke(obj);
}
{/collapse-item}
{collapse-item label="折叠标题二"}
折叠内容二
{/collapse-item}
评论 (0)