DEV Community

Discussion on: if-then, a statement in Java; but an expression in Kotlin

Collapse
 
sergivb01 profile image
sergi

You can actually do this in Java.

String message = (answer == correctAnswer) ? "You are correct" : "Try again";
Collapse
 
tedhagos profile image
Ted Hagos

Yes you can, but that's the ternary operator (Kotlin has that as well, they call it the "Elvis" operator). The article was just pointing out the slight differences between Kotlin and Java; one of them being some statements in Java are treated as expressions in Kotlin.