Sobes.tech
Intern

What is the difference between val and var in Kotlin?

sobes.tech AI

Answer from AI

val (value) is used to declare immutable variables. Once a value is assigned, it cannot be changed.

var (variable) is used to declare mutable variables. Its value can be changed at any time.

// Usage examples
val immutableValue = 10 // Cannot be changed
var mutableValue = 20  // Can be changed
mutableValue = 30
What is the difference between val and var in Kotlin… - sobes.tech