November 2018
Intermediate to advanced
388 pages
9h 5m
English
To declare a variable in Kotlin, we use either the val or var keywords.
Let's take a look at the following example:
val number = 10println(number)
The preceding code prints the value that is assigned to a variable number, as can be seen in the following screenshot:

However, if we try to change the value assigned to the number, we will get a compilation error. Take a look at the following code:
val number = 10println(number)number = 11println(number)
The output is as follows:

This is because val is immutable in Kotlin. This ...
Read now
Unlock full access