What's the difference?
Kotlin provides two ways to define variables:
var. What's the difference? You can change
var variables as many times as you want. But once you set a
val variable, you can't update again. Here's an example:
val firstName = "Daniel" // always stuck with "Daniel", can't change anymore
From now on, you can't change
firstName; it's set in stone. However, had I created
var, I can change it:
var firstName = "Daniel" firstName = "Dan" firstName = "John" firstName = "Don"
In general, prefer
val, unless the variables needs to change.