可以初始化字段的值吗?
我能够从超类
中获取子类中的字段Field[] fields = this.getClass().getDeclaredFields();
for(Field field : fields) {
//I need to assign a value to every field depending on their type
if(Integer.class.isAssignableFrom(field.getType())) {
//Something like this
field = (Integer) 100;
} else if(MyObject.class.isAssignableFrom(field.getType())) {
//Something like this
field = new MyObject();
}
}