In Java, is there a way to store, edit, convert, print, access, evaluate and compare blocks of code (possibly user entered), while also being able to execute them?
An example for where this would be useful is if someone codes an software that is designed to teach people how to code, where the user would input code to the system, and the program would check if the user developed code is
I'm looking for something like this:
CodeBlock line20And21 = `String x = "hello"; System.out.println(x);`; // stores a block of code
line20And21.replace("ln",""); //edits the block of code
System.out.println(line20And21.toString()); // converts/prints the block of code
CodeBlock usersCode = Scanner.nextCodeBlock(); // accesses block of code
if(! line20And21.wouldThrowError()); // evaluates block of code
if(line20And21.wouldDoTheSameThingAs(line18And19)) // compares blocks of code
line20And21.execute(); // executes the block of code
The code I would be using is of course much more complicated than just defining a String and printing it, but I'm sure the idea would be the same. I really appriciate any help with this. Thanks!