package cn.zxj.reflex;
public class Demo {
private String propertyName;
}
package cn.zxj.reflex;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
public class Test {
public static void main(String[] args) throws Exception {
Class c = Class.forName("cn.zxj.reflex.Demo");
Constructor constructor = c.getConstructor();
Object o = constructor.newInstance();
Field propertyName = c.getDeclaredField("propertyName");
propertyName.setAccessible(true);
propertyName.set(o,"123");
System.out.println(propertyName.get(o));
}
}