Consider this code:
val x1: Byte = 0x00
val x2: Byte = 0x01
val x3: Byte = x1 + x2;
This gives a compile error, because the result of adding 2 Byte
s is an Int
.
To work around this, I need to manually cast the result back into a byte:
val x3: Byte = (x1 + x2).toByte()
This is very counter-intuative. Why do the arithmetic operators work like this?