如何将字符串作为代码运行? [英] How do you run a string as code?
本文介绍了如何将字符串作为代码运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
将字符串转换为代码
Possible Duplicate:
Convert String to code
我有一个程序,需要能够将字符串作为代码执行.例如,我将有一个字符串读取:
I have a program that needs to be able to execute a string as code. For example, I would have a string that reads:
public void do(int a, int b){
a++;
b--;
System.out.println(a);
System.out.println(b);
}
现在,如何获取程序来执行该字符串?
Now, how do I get the program to execute that string?
推荐答案
You can wrap this string in a class and compile it with Java Compiler API. You would have to be running JDK instead of JRE.
这篇关于如何将字符串作为代码运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文