Kotlin has two keywords for declaring variables, val and var. The var variable is a mutable variable, that is, a variable that can be changed to another value by reassigning it. This is equivalent to declaring a variable in Java:
var name = "kotlin"
In addition to this, the var variable can be initialized later:
var name: String name = "kotlin"
Variables defined with var can be reassigned, since they are mutable:
var name = "kotlin" name = "more kotlin"
The val keyword is used to declare a read-only variable. This is equivalent to declaring a final variable in Java. A val variable must be initialized when it is created, since it cannot be changed later:
val name = "kotlin"
A read-only variable does not mean the instance itself is automatically immutable. The instance may still allow its...