Is there a Java equivalent Python Eval function?

Is there a Java equivalent Python Eval function?

This will be a function that uses an arbitrary string and attempts to execute it in the current context

Solution

Based on this Java tip, if you want to use COM sun. tools. javac. Main. Compile (source), you can compile Java strings on the fly

com. sun. The classes in tools are certainly not part of the official Java API

There is a compiler API in Java 6 to provide programmatic access to the compiler See the document for interface javacompiler

Any standard API does not provide direct Eval, but the existing tools build their own If you try to perform a completely generic Eval, you may have "JVM internal JVM" problems, so it's best to limit what you want to do

See also: is there an eval() function in Java? Some good comments and explanations

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>