Hello! This code is not compiling: ```var b : Byte...
# compiler
p
Hello! This code is not compiling:
Copy code
var b : Byte = 10.toByte()
b += 10.toByte()
Complains about type mismatch: Required Byte got Int. Why?
e
Copy code
operator fun Byte.plus(other: Byte): Int
e
Bytes are designed for storage, so that you can have a lot of bytes in memory. They are not designed for doing arithmetics (that’s what
Int
and
Long
are for). So, do you arithmetics in Ints, then coerce and store to bytes if needed.
🙏 1
p
Thanks!