java 动态编译测试
测试代码:
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
public class MainTest {
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, UnsupportedEncodingException {
String sourceCode="public class MainTest {\r\n" +
" public static void main(String[] args) {\r\n" +
" A a=new A();\r\n" +
" System.out.println(a.a);\r\n" +
" }\r\n" +
"}\r\n" +
"class A{\r\n" +
" public int a=9;\r\n" +
"}";
MyJavaCompiler c=new MyJavaCompiler(sourceCode);
if(c.compiler()) {
c.runMainMethod();
System.out.println("编译时间(ms):"+c.getCompilerTakeTime());
System.out.println("运行时间(ms):"+c.getRunTakeTime());
System.out.println("运行结果输出:"+c.getResult());
}
System.out.println("编译信息:"+c.getCompilerMessage());
}
}
编译时间(ms):26
运行时间(ms):1
运行结果输出:9
编译信息:
fixed
没有一个冬天不可逾越,没有一个春天不会来临。最慢的步伐不是跬步,而是徘徊,最快的脚步不是冲刺,而是坚持。