Giorgi
01/22/2025, 10:41 AMfun byteInWhen() {
val event: Byte = 1
when (event) {
1 -> "one",
2 -> "two",
else -> "other"
}
}
The issue is "Incompatible types: Int and Byte". So how do I write the when statement? I could use .toByte() but seems ugly and wrongHuib Donkers
01/22/2025, 11:07 AMwhen (event.toInt())
. Curious if there's a better way..rkechols
01/23/2025, 5:12 AM1
only auto-cast to Int
or larger types, and there's no syntax for direct byte literals (like f
for floats or L
for longs).
Getting it down to a smaller type like Byte
just requires a cast/conversion.
Or like Huib said you can cast/convert the Byte
up to an Int
https://kotlinlang.org/docs/numbers.htmlcalidion
01/23/2025, 10:13 AMenum class EventT {
ONE,
TWO,
OTHER
}
fun main() {
var e = EventT.ONE
when(e) {
EventT.ONE -> println("One")
else -> println("Other")
}
}
Giorgi
01/23/2025, 11:21 AMcalidion
01/23/2025, 11:27 AMcalidion
01/23/2025, 11:27 AM