Is there a way to evaluate a String in Kotlin like JavaScript's eval()?
For example:
var str = "var x = 5"
eval(str)
println(x) //Y que muestre por pantalla 5
Is there a way to evaluate a String in Kotlin like JavaScript's eval()?
For example:
var str = "var x = 5"
eval(str)
println(x) //Y que muestre por pantalla 5
What you are looking for is called scripting and this is supported since version 1.1 using the
javax.script
. Here an example of its use :There is also a project on github with examples of how to use the API available.