通过javassist来修改class内的方法

ClassPool pool = ClassPool.getDefault(); 
CtClass cc = pool.get("com.text.TestClass"); 
  
CtMethod method = cc.getDeclaredMethod("main");
method.setBody("System.out.println(\"Hello,world.\")");
cc.writeFile("bin/");

 

你可能感兴趣的:(javassist)