Hi,How it is possible to return array of items if there is when inside, how should I modify the else bracnh to get it working
fun printAll(type: Int): Array<String> { // 1
return arrayOf(
when(type) {
1 -> "one"
2 -> "two"
else -> {
"three","four"
}
}
)
}
I dont like repetition of code, thereforeI would like the arrayof statment before when
j
Johann Pardanaud
10/21/2022, 3:28 PM
well, you can’t without adding runtime computations, which is not worthwhile if you ask me
the repetition here is not that much and at least your code is way more readable 😉