Hey, at what point is the value converted to Int i...
# announcements
a
Hey, at what point is the value converted to Int in Kotlin? AS is showing a warning that Byte is expected but found Int even though in the Java version of the code it is picked up as byte. Kotlin: var r = byteArray[3 + i] If (r > 0) r += 255 //the warning is shown here Java: byte r = byteArray[3 + i] If (r > 0) r += 255; //the warning is not shown
g
It’s correct. Kotlin is designed to be explicit for such implcit type convertations
a
I think I got it, thanks
s
and the way to be explicit about it is to cal
r.toInt()
. But you use the += operator, so you would need to reasign. So better start of with an int.
Copy code
var r = byteArray[3 + i].toInt()
if (r>0) r+= 255