- public class Test {
- public static void main(String[] args) throws Exception {
- Class cls = Class.forName("Cls");
- //得到成员
- Field f = cls.getDeclaredField("x");
- //设置访问权限
- f.setAccessible(true);
- System.out.println(f.get(new Cls()));
- }
- }
- class Cls{
- private int x = 123;
- }
复制代码 |