Why is the 'when' expression in kotlin saying it's not exhaustive?
Example:
fun describe(x: Int): String {
when (x) {
1 -> return "One"
2 -> return "Two"
}
}
Solution:
fun describe(x: Int): String {
return when (x) {
1 -> "One"
2 -> "Two"
else -> "Unknown" // Handling all other cases
}
}
In Kotlin, when using the `when` expression as an expression (i.e., returning a value), you need to make sure it's exhaustive and handles all possible cases, including an `else` clause.