What is the difference between the keywords
Kotlin? If you’re coming from
val refers to variable that cannot be updated after it has been assigned a value; while
var is the usual writable variable whose value can always be changed by other codes.
“val” is like “final” in Java
Consider the following codes from
Line 14 causes compilation error as it is not allowed to change the value of a
final variable after it has been initialized to some value.
Line 13 causes a compilation error as
val variables’ values are unchangeable.
“var” variables are modifiable
var are non-constant variables whose values can be changed anytime.
// In Kotlin
var name = "Turreta"
var name = "www.turreta.com"