The code below gives me the following error.
Error: Type mismatch: inferred type is kotlin.Int but kotlin.Byte was expected
var temp: Byte = 0
var temp2: Byte = 1
temp += temp2
Is there any way around this in kotlin or am I not allowed to use the += or -= operators with Byte? Is plus equals overloaded for Long and Int but not Byte and Short?
According to kotlin docs Byte's plus/minus operations with other Byte will result in an Int. So while you think it is weird try to add Byte with value of 255 to other Byte with calue of 255 ;)
I think they made it on purpose. If you are certain that your result is still within Byte bounds then just use Int.toByte() and the end of the calculations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With