October 2018
Intermediate to advanced
370 pages
9h 15m
English
Converting data from one type to another is called type casting, for example, conversion from Float to Integer, or from Double to String. With Java or C++, type casting is a very straightforward process because these languages have primitive data types. Look at the following Java example:
double d = 10.50;int i = (int) d;
In Kotlin, everything is an object and so it requires some extra steps to type cast from one type to another. However, Kotlin provides a rich library that helps perform these conversions. Let's explore this with the following example. Create a Byte variable and assign a value of 10 to it. Create an Integer variable and attempt to assign byteValue to intValue:
var byteValue : Byte = 10var intValue : IntintValue ...
Read now
Unlock full access