-1

What is the equivalent of this expression in Kotlin.

a ? b : c

This is giving error.

Saikrishna Rajaraman
  • 3,205
  • 2
  • 16
  • 29
Yash
  • 64
  • 4
  • 1
    Oh dear... typing exactly that into your favorite search engine delivers tons of results, one of which is: https://stackoverflow.com/questions/16336500/kotlin-ternary-conditional-operator (which was probably also highlighted while you entered your question) ... actually it is an "exact" duplicate... – Roland Aug 10 '18 at 12:36
  • I feel like I answered this question like 8 hours ago https://stackoverflow.com/questions/51779334/ternary-operator-in-kotlin/51782206#51782206 and even that was a duplicate – EpicPandaForce Aug 10 '18 at 13:08

1 Answers1

3

In Kotlin, if statements are expressions. So the following code is equivalent:

if (a) b else c

Hope it's working for you.

Rashpal Singh
  • 633
  • 3
  • 13