3

how to evaluate/execute String expression as a code in Scala

Example

var data = "1+2"
prinln(eval(data))

>>> 3

So, in the above expression 1+2 is String, as there are double quotes around it. But on evaluation, it executed as arithmetical expression and answer is 3

Similarly, I have some dynamic scala code which is in the form of String, so I want to execute that.

I tried to search but didn't get anything. Any idea?

Logan
  • 926
  • 1
  • 10
  • 18
Tarun Khaneja
  • 451
  • 11
  • 23
  • https://stackoverflow.com/questions/39142979/dynamic-code-evaluation-in-scala#39143272 – chandra Oct 16 '18 at 14:40
  • The "already has an answer" text should indicate the correct answer, lest anyone assume the green check is still optimal. Does anyone assume that? https://stackoverflow.com/a/16883871/1296806 – som-snytt Oct 16 '18 at 22:16

0 Answers0