Eugen Martynov
08/21/2025, 8:26 AMelse case for
fun getText(ignoreOptions: Boolean, option: Option): String {
return when {
ignoreOptions -> "Ignored"
option is OptionA -> "A: ${option.number}"
option is OptionB -> option.text
}
}
When Option sealed class and has only OptionA and OptionB as implementationsEugen Martynov
08/21/2025, 8:29 AMwhen if it would be something like when(ingoredOption, option){} to give copmpiler glimpse it is only things I'm interested here.Benoit Quenaudon
08/21/2025, 8:30 AMfun getText(ignoreOptions: Boolean, option: Option): String {
if (ignoreOptions) return "Ignored"
when (option) {
is OptionA -> "A: ${option.number}"
is OptionB -> option.text
}
}Vampire
08/21/2025, 10:42 AMs/when/return when/ 🙂Youssef Shoaib [MOD]
08/21/2025, 1:02 PMfun getText(ignoreOptions: Boolean, option: Option): String {
return when (option) {
else if ignoreOptions -> "Ignored"
is OptionA -> "A: ${option.number}"
is OptionB -> option.text
}
}Vampire
08/21/2025, 1:17 PMVampire
08/21/2025, 1:19 PMVampire
08/21/2025, 1:19 PMCLOVIS
08/22/2025, 8:20 AM