JAVA:技术-ClassLoader
导入包:
<dependency>
<groupId>net.openhft</groupId>
<artifactId>compiler</artifactId>
<version>2.3.1</version>
</dependency>
主程序:
public static void main(String[] args) throws Exception {
String className = "mypackage.MyClass";
String code1 = "package mypackage;\n" +
"public class MyClass implements Runnable {\n" +
" public void run() {\n" +
" System.out.println(\"Hello World\");\n" +
" }\n" +
"}\n";
Class aClass = CompilerUtils.CACHED_COMPILER.loadFromJava(className, code2);
Runnable runner = (Runnable) aClass.newInstance();
runner.run();
PYTHON:exec函数
if __name__ == '__main__':
print("main----")
a = "([1,2],[3,4],[5,6])"
print(type(a))
b = eval(a)
print(type(b))
print(b)
a = 5
b = 10
print(a + b)
program = 'a=5\nb=10\nprint(a+b)'
exec (program)