Java: treat String as a command without using exec

Status
You're currently viewing only ramases's posts. Click here to go back to viewing the entire thread.

ramases

Ars Tribunus Angusticlavius
9,024
Subscriptor++
But now I wanna know, in Java (or Kotlin), how do I treat a string like a line of code?

The JVM ecosystem has a ... strong cultural aversion to this type of data/code commingling, due to the dangers it brings.

The traditional way to have dynamic code generation and execution on the JVM is to use something like Javassist (https://github.com/jboss-javassist/javassist) or ByteBuddy (https://github.com/raphw/byte-buddy) to generate a type with whatever behaviour you want it to have, then call it.

If you really want to, you can use something like JShell or BeanShell.
 
Status
You're currently viewing only ramases's posts. Click here to go back to viewing the entire thread.