标签:两种 article 推荐 exce 调用 rom obj com user
try {
Properties prop = new Properties();
prop.load(new FileInputStream(
"F:\\user.properties"));
Class class1 = Class.forName("com.zlkj.config.User1");
Object newInstance = class1.newInstance();
//这样就可以拿到本类中公有和私有方法
Field[] fields = class1.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
field.set(newInstance, prop.getProperty(field.getName()));
}
System.out.println(newInstance.toString());
} catch (Exception e) {
e.printStackTrace();
}
有时候可能要拿父类的属性,调用 getSuperClass().getDeclaredFields()
本文由博客一文多发平台 OpenWrite 发布!
标签:两种 article 推荐 exce 调用 rom obj com user
原文地址:https://www.cnblogs.com/Lyn4ever/p/11756000.html