Type inference

Type inference is a mechanism in which the Kotlin compiler plays its role to find out a variable type. Kotlin will determine the data type by understanding the value assigned. It intelligently infers the type by the value and then makes the variable of the data type respectively. This technique is called type inference. In all the previous code, whether a data type is declared with val or var are examples of type inference:

val age = 25
val name = "Bob"

In the preceding code, age is an integer and name is a string type variable. The type of these variables is inferred by the compiler.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.210.91