miqbaldc
06/18/2021, 6:28 AMfun doSomething(): String {
return if
aMethodHere1()
else
aMethodHere2()
}
2️⃣
fun doSomething(): String {
return if aMethodHere1()
else aMethodHere2()
}
3️⃣
fun doSomething(): String {
return if aMethodHere1() else aMethodHere2()
}
Michael Böiers
06/18/2021, 6:38 AMthanksforallthefish
06/18/2021, 6:51 AM{}
and still avoid gotofailmiqbaldc
06/18/2021, 8:09 AMhho
06/18/2021, 8:48 AMif
hasn't any conditionMichael Böiers
06/18/2021, 8:52 AMwhen
and to go without method body. The arrows make it very obvious what’s happening, as opposed to the if condition parentheses.
fun isSpecial(x: Int) = when {
x == 42 -> "very"
else -> "dunno"
}
gildor
06/21/2021, 3:29 AMfun doSomething(): String = if (...) {
aMethodHere1()
} else {
aMethodHere2()
}
when
as suggested by Michael also an option, but I usually avoid when which has only one condition, it looks more natural for me to use if/else for such case
PS It would be better to fix snipper and use valid Kotlin code, if you add correct condition to if
this code will look quite differently in terms of style