How to insert java file inside code in Java

I wanted to know if there is a way to import the dynamic code change code into the main encoding. Something like that:

Main:
int x;
(insert input.java)

      

Input.java content:

x = 2;

      

Is it possible to import the code internally input.java

into the main code?

+3


source to share


2 answers


There are no directives in Java at source compile time.

Also it has no rating for evaluating Java source code at runtime.



The only real way to get new Java code in an executable Java virtual machine is by loading classes.

However, since the advent of javax.script (Java 6), a reasonably supported runtime environment (like Java 8's Nashorn Javascript implementation) can import and evaluate some script code that is fed back into the Java API. This is a huge question and too big to study in depth here.

+6


source


Java has no equivalent eval

or any other construct capable of evaluating code at runtime. It is excellently capable of parsing external data such as XML and taking action on what it finds. It can also run and dump output from external processes, which could very well be dynamically generated code. The details of this process depend on your OS.



0


source







All Articles