working with generic numbers of type `N : Number`....
# announcements
e
working with generic numbers of type
N : Number
. If I have a comparison shall I cast
if((v as Int) == (vCur as Int))
or I can leave it plain
if(v == vCur)
?
r
Why would you cast as
Int
. Who says a
Number
is an
Int
e
I know under specific conditions (external enum)
r
Comparing two
Number
isn’t an easy task, I guess you need to check all the equals implementations to see how that works
For example
1f.equals(1.0)
is false
e
yeah, but if I have the certainty that they have the same type..?
I guess I shall be safe, but I'd like a feedback about it
r
I don’t know where to find the implement of equals for the numbers
But basically if for example
Float.equals(other: Any?)
calls
Float.equals(other: Float)
is other is of type
Float
, then you should be safe. I expect that it’s how it should work already, but you’re right to want some confirmation
I would just write tests for it
👍 1
d
Number is an abstract class, Int implements compareTo(), so it will be called, you can leave v == vCur
e
ok, I'll leave it plain and write some test for safety, thanks both