![]() Numbers with a decimal (like 2.0) will default to a Double, so if you want a Float you need to declare a Float, as shown in the last example. ![]() In the first four examples, if you don’t explicitly specify a type, the number 1 will default to an Int, so if you want one of the other data types - Byte, Long, or Short - you need to explicitly declare those types, as shown. How to declare variables of the basic numeric types: val b: Byte = 1 Kotlin comes with the standard numeric data types you’d expect, and in Kotlin all of these data types are full-blown objects - not primitive data types.
0 Comments
Leave a Reply. |