Variables in Kotlin are of 2 types –
Mutable Variables – Can be reassigned. “var” is used to define mutable variables.
Immutable Variables – Can’t be reassigned. “val” is used to define immutable variables.
var can be reassigned. For example – var age = 4; age = 5
We created a variable age with the value of 4 and then we assigned the value to 5, so var can be reassigned.
But val can’t be reassigned. For example – val age = 5; age = 6
We created a variable age with the value of 6 but when we try to reassign it to 6, Android Studio throws the error “Change ‘val’ to ‘var’”.