Class c = Class.forName("Hello");
Object obj = c.newInstance();
Field field = c.getDeclaredField("name");
field.set(obj, "zhangsan");
public class Hello {
int age;
String name;
}
调用newinstance()方法创建对象时,该行代码是否相当于 Object obj = new Hello();(多态?)
那当field.set时为什么可以直接填写obj来设置name?(父类型引用直接访问了子类型中的属性?)