Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 291
Shaheen Ahamed S Avatar asked Sep 16 '25 10:09

Shaheen Ahamed S


1 Answers

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…)

like image 138
gidds Avatar answered Sep 18 '25 05:09

gidds