Akbar09/04/2019, 2:48 PM
Luke09/04/2019, 2:56 PM
is an expression. You can do
. See https://kotlinlang.org/docs/reference/control-flow.html
val a = if (condition) "something" else "something else"
Casey Brooks09/04/2019, 2:57 PM
statements are expressions in Kotlin (they return a result) and so can be used to do exactly the same thing as the ternary operator, but is less confusing.
is the same as
a = b ? c : d
a = if(b) c else d
DALDEI09/04/2019, 3:34 PM
Sam09/04/2019, 4:50 PM
works well as a shorthand ternary dealing with nulls.
a = nullableValue ?: nonnullDefaultValue
Akbar09/05/2019, 6:45 AM