Search code examples
kotlinevalkeyword

Use of eval keyword in Kotlin


What is use of eval() during safe cast and smart cast in kotlin?

Is it similar to eval() which we use in javascript, python or any other language?


Solution

  • The eval() function is only available in Kotlin/JS , and simply calls the JavaScript eval() function.

    This means you can't use it in code you might want to run on Kotlin/JVM or Kotlin/Native.

    (Also, while I'm not familiar with Kotlin/JS, I'd imagine that could be quite powerful and also quite dangerous, so maybe caution is indicated…)