October 2018
Intermediate to advanced
370 pages
9h 15m
English
The val keyword is a read-only variable that is used to declare an immutable variable. Immutable means that once the variable is assigned, it will remain the same until the end of the application's life:
val age = 25
In the preceding code line, val is a keyword, age is a variable name, and 25 is an integer value assigned.
val is the same as var; the variable type is dependent on the value assigned to the variable.
Once the variable is declared, it is not possible to update it under any circumstances. This feature becomes more important when we are writing a complex application or a program of scientific calculations:
val pi = 3.14159
Knowing ...
Read now
Unlock full access