0

In c++ const can be defined by

void func(const int param) {
    const int VALUE = param > 0 ? param : 0;
    ...
}

In Kotlin I am trying to use when:

fun func(param: Int) {
    val VALUE = when(param)
    when(param) {
        param > 0 -> param // Error: expression `param > 0` is not Int
        else -> 0
    }
    ...
}

What is the kotlin way to say expression ? value0 : value1?

r0n9
  • 2,505
  • 1
  • 29
  • 43
  • Does this answer your question? [How to write ternary conditional operator?](https://stackoverflow.com/questions/16336500/how-to-write-ternary-conditional-operator) – aSemy May 31 '22 at 13:47

1 Answers1

1

Kotlin if one line like this :

 var yourVAr=if(condition)value1 else value2
Aymen Ben Salah
  • 489
  • 4
  • 13