Consider code example:
val contentLength :Long? = 1
val float = contentLength?.toFloat()
val any = (float ?: 0) * 1.25
// ^
// compilation error here
If I try to extract variable herem like that:
val casted = (float ?: 0)
IDE shows that casted has Any as type. Why it happens? How to get nullsafe float value from float reference and multiply it to another float value?
UPDATED
Replacing 0 with 0.0:
(float ?: 0.0)
has no effect. :(
Change the line
val any = (float ?: 0.0) * 1.25
to
val any = (float ?: 0.0f) * 1.25f
Else you mix double and float what leads to the compile error
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