You need the equivalent JavaScript JavaScript. There is no equivalent in Java.
Well, there is, but it is not trivial.
You can generate the full source code of the class containing this code. Sort of
public class StuffToDynamicallyCompile { public static final void main(String[] ignored) { PUT STUFF HERE! } }
And then programmatically call the compiler, as described in this answer , or as indicated in the comments: How to compile .java from a java program
Not an easy task. Perhaps there is a way to minimize your requirements, so you can enable an extremely limited set of commands and just execute it with the switch ("if" dothis ", then call doThis() , otherwise if" doThat ", call doThat() , and etc.).
source share