| 39 | cc.writeFile(""); |
| 40 | } |
| 41 | public static void usingStudent() throws Exception{ |
| 42 | ClassPool pool = ClassPool.getDefault(); |
| 43 | CtClass cc = pool.getCtClass("src\\test\\java\\examples.Student"); |
| 44 | // 实例化 |
| 45 | Object student = cc.toClass().newInstance(); |
| 46 | // 设置值 |
| 47 | Method setName = student.getClass().getMethod("setName", String.class); |
| 48 | setName.invoke(student, "junjie"); |
| 49 | // 输出值 |
| 50 | Method execute = student.getClass().getMethod("printName"); |
| 51 | execute.invoke(student); |
| 52 | } |
| 53 | public static void main(String[] args) throws Exception{ |
| 54 | createStudent(); |
| 55 | usingStudent(); |