Does anybody know why calling `toByte()` on `-128`...
# announcements
n
Does anybody know why calling
toByte()
on
-128
results in
128
? Java bytes can only hold
-128
to
127
anyways! Example code:
Copy code
fun main(args: Array<String>) {
    println(-128.toByte())
    println(-127.toByte())
}
Result:
Copy code
128
-127
Casting
-128
to
byte
in Java returns
-128
as expected.
u
Interesting enough, factoring out the number to a local val fixes the issue:
Copy code
fun main(args: Array<String>) {
    val v1 = -128
 	println(v1.toByte())
    val v2 = -127
 	println(v2.toByte())
}