java - 可以将字符串编译为代码吗?

标签 java android compilation


我有一个获取 html 文件内容的应用程序。

假设页面的文本是:

String[] arr = new String[] {"!","@","#"};
for (String str :  arr) {
write(str);
}

我能否以某种方式编译此文本并在我的应用程序中运行代码?

谢谢

最佳答案

使用Janino .它是一个 Java 运行时内存编译器。比 BCEL 之类的要容易得多。

来自主页:

“什么是贾尼诺?

Janino is a super-small, super-fast Java™ compiler. Not only can it compile a set of source files to a set of class files like the JAVAC tool, but also can it compile a Java™ expression, block, class body or source file in memory, load the bytecode and execute it directly in the same JVM. Janino is not intended to be a development tool, but an embedded compiler for run-time compilation purposes...

关于java - 可以将字符串编译为代码吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11925497/

相关文章:

linux - Haskell ghc 编译/链接错误,未创建可执行文件。 (Linux)

java - 为什么会出现空指针异常?

Android 应用程序不能在 3G 网络中工作,但可以在 WIFI 中工作

c++ - 为什么在添加更多变量和/或指令时程序大小保持不变?

android - API 级别 > 3.0 中的操作栏,但仍支持 API < 3.0

android - 如何在 onSaveInstanceState() 中存储值并检索?

compilation - 在后台运行:make from gVim

java - Jmeter抛出NoSuchMethodException,但该方法确实存在

java - 无法使用eclipse创建android应用程序

java - JasperReports API : calling JasperCompileManager. compileReport (String) 方法引发了 MalformedByteSequenceException 异常