Пример #1
0
 @Test
 public void test2()
     throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
   People p = new People("Hana", 25, 170);
   Class<? extends People> clazz = p.getClass();
   Method m = clazz.getDeclaredMethod("print");
   m.invoke(p);
 }
Пример #2
0
  @Test
  public void test1() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
    People p = new People("Hana", 28, 190);
    System.out.println("변경 전 : " + p.getName());

    Class clazz = p.getClass();
    //		Field[] fields = clazz.getDeclaredFields();
    Field f1 = clazz.getDeclaredField("name");
    f1.setAccessible(true);
    f1.set(p, "Lee");

    System.out.println("변경 후:" + p.getName());
  }