Why can’t I do this: ```val myByte: Byte = 0; val ...
# getting-started
r
Why can’t I do this:
Copy code
val myByte: Byte = 0;
val myInt: Int = 0;
myByte == myInt;
but CAN i actually do this?
Copy code
myByte.compareTo(myInt) == 0;
Isn’t it the same?
v
No, Byte and Int are different types. You cannot compare different types with
==
. But
Byte.compareTo
is overloaded with
Byte.compareTo(Int)
, thus it works. You can do
myByte.toInt() == myInt
r
Okay, too bad it can’t do some sort of smart casting so we can use the simple comparison syntax. But I guess I’ll use the compareTo syntax, seems more flexible in case I change types