二、栗子

2.、使用举例

  1. //源码字符串
  2. String codeStr = "package org.hocate.test; "
  3. + "import org.voovan.tools.TString; "
  4. + "public class testSay { "
  5. + " public String say(){ "
  6. + " System.out.println(\"helloword\"); "
  7. + " return TString.removePrefix(\"finished\"); "
  8. + " } "
  9. + "} ";
  10. //在日志平台输出源码
  11. Logger.simple(codeStr);
  12. //构造编译对象
  13. Complier dc = new Complier();
  14. //编译代码
  15. dc.compileCode(codeStr);
  16. }
  17. public void testRun() throws Exception{
  18. //使用反射工具类实例化对象
  19. Object testSay = TReflect.newInstance("org.hocate.test.testSay");
  20. //使用反射工具执行方法
  21. Object obj = TReflect.invokeMethod(testSay, "say");
  22. //在日志平台输出源码
  23. Logger.simple(obj);
  24. }