I wanted to know if there was a way to import the code of dynamic changing code into the main coding. Something like this:
Main:
int x;
(insert input.java)
Contents of input.java:
x = 2;
Can I import the code inside input.java to the main code?
Java does not have include directives at source compilation time.
Neither does it have an eval for evaluating new Java source code at runtime.
The only real way to get new Java code into a running Java VM is via classloading.
However, since the advent of javax.script (Java 6), a sufficiently supported runtime (e.g. the Nashorn Javascript implementation from Java 8) could import and eval some scripting code that called back into a Java API. This is a huge subject & too big to address in depth here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With