Is there a way to do something like the following example implies in Java?
public class HandleCode
{
public static void main(String[] args)
{
String someCode = "System.out.println(aNumber);";
int aNumber = 123;
pasteCode(someCode); // Here we somehow tell Java to paste in at pre-compile time the text that is stored in someCode and treat it as source-code text.
}
private static void pasteCode(String code)
{
// Method code here
}
}
This hypothetical code would print: 123
Is there such a way to code pasteCode
method to do this in Java? I know this is possible to do in C++ thanks to some pre-compiler commands, but I was wondering how this is done in Java.