Why doesn't this work:
var color: Int = 0xFF0000FF
and why do I have to call toInt()
var color: Int = 0xFF0000FF.toInt()
Error: Kotlin: The floating-point literal does not conform to the expected type Float - Stack Overflow I was making a simple maths calculator in kotlin, an error appeared on my screen when I tried to initialize the value of one of the variables used as 0.00 for float integer.
Kotlin Literals 2 So in the previous post we have seen that Kotlin only supports positive integer literals, which means that half the numbers it supports can't be written as a literal in code. Let's look at other ways to write number literals, maybe as hexadecimal.
14 Declaring Byte in Kotlin does compile-time error 'The integer literal does not conform to the expected type Byte' 264 How does the reified keyword in Kotlin work?
// does NOT work. You’ll get a "The integer literal does not conform // to the expected type Float/Double" error if you don’t append the f or .0. // is fine. Kotlin uses the expected symbols for most operators — + for addition, — for subtraction, * for multiplication, / for division, % for mod — so I won’t go over those.
This is a bug in the compiler, feel free to vote / watch it: https://youtrack.jetbrains.com/issue/KT-2780
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