There is no ` ? : ` in kotlin
# getting-started
s
There is no
? :
in kotlin
👍 3
n
In Kotlin, you don’t need ternary. You can easily write this:
val str = if (exp) "true" else "false"
However, you can’t write this in Java like that so that’s the reason of ternary has born.
String str = exp ? "true" : "false"
I think if else structure is much more readable.
c
Also ? : Is Elvis operator in kotlin it is use when you want to assign alternate value when the actual value is null example val str= exp?:"not_found" .. so if exp is a null then not_found till be assigned to the str variable.