How could I call Java code dynamically?

后端 未结 4 1152
春和景丽
春和景丽 2020-12-10 23:20

How could I write Java code that is executed like javascript code used together with the eval function?

What I would like to achieve would be something like this:

相关标签:
4条回答
  • 2020-12-10 23:52

    Look into BeanShell or Groovy. Both will give you reasonable solutions--but those solutions rely on my interpretation of your problem, which may be flawed.

    0 讨论(0)
  • 2020-12-10 23:52

    I've used the JavaScript engine shipped with Java 6 and it works quite well. The performance of the engine is very very decent.

    Check the page http://java.sun.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html

    0 讨论(0)
  • 2020-12-10 23:58

    For completeness sake, the Compiler API is coming in the next version of Java..

    0 讨论(0)
  • 2020-12-11 00:10

    I believe the compiler API is present in the current Java SE 6. See the javadoc.

    See this blog post for details and an example.

    0 讨论(0)
提交回复
热议问题