- public static void main(String[] args) throws Exception {
- Class clazz = Person.class;
- Constructor c = clazz.getConstructor(String.class,int.class);
- Person p = (Person) c.newInstance("张三",23);
-
- Field f = clazz.getDeclaredField("name");
- f.setAccessible(true); //去除私有权限
- f.set(p, "李四");
-
- System.out.println(p);
-
- }
复制代码 代码中有一块是去除私有权限,想问,这个去除私有权限,是去除在主方法中调用类时的私有权限,还是去除了Person类中name字段的私有权限.
|
|