@@ -130,33 +130,33 @@ public class Main {
130130 /**
131131 * 获取TargetObject类的Class对象并且创建TargetObject类实例
132132 */
133- Class<?> tagetClass = Class . forName(" cn.javaguide.TargetObject" );
134- TargetObject targetObject = (TargetObject ) tagetClass . newInstance();
133+ Class<?> targetClass = Class . forName(" cn.javaguide.TargetObject" );
134+ TargetObject targetObject = (TargetObject ) targetClass . newInstance();
135135 /**
136136 * 获取所有类中所有定义的方法
137137 */
138- Method [] methods = tagetClass . getDeclaredMethods();
138+ Method [] methods = targetClass . getDeclaredMethods();
139139 for (Method method : methods) {
140140 System . out. println(method. getName());
141141 }
142142 /**
143143 * 获取指定方法并调用
144144 */
145- Method publicMethod = tagetClass . getDeclaredMethod(" publicMethod" ,
145+ Method publicMethod = targetClass . getDeclaredMethod(" publicMethod" ,
146146 String . class);
147147
148148 publicMethod. invoke(targetObject, " JavaGuide" );
149149 /**
150150 * 获取指定参数并对参数进行修改
151151 */
152- Field field = tagetClass . getDeclaredField(" value" );
152+ Field field = targetClass . getDeclaredField(" value" );
153153 // 为了对类中的参数进行修改我们取消安全检查
154154 field. setAccessible(true );
155155 field. set(targetObject, " JavaGuide" );
156156 /**
157157 * 调用 private 方法
158158 */
159- Method privateMethod = tagetClass . getDeclaredMethod(" privateMethod" );
159+ Method privateMethod = targetClass . getDeclaredMethod(" privateMethod" );
160160 // 为了调用private方法我们取消安全检查
161161 privateMethod. setAccessible(true );
162162 privateMethod. invoke(targetObject);
@@ -177,6 +177,6 @@ value is JavaGuide
177177** 注意** : 有读者提到上面代码运行会抛出 ` ClassNotFoundException ` 异常,具体原因是你没有下面把这段代码的包名替换成自己创建的 ` TargetObject ` 所在的包 。
178178
179179``` java
180- Class<?> tagetClass = Class . forName(" cn.javaguide.TargetObject" );
180+ Class<?> targetClass = Class . forName(" cn.javaguide.TargetObject" );
181181```
182182
0 commit comments