In Kotlin, "val" is a keyword used to declare read-only or immutable variables. It is short for "value" and signifies that the variable cannot be reassigned after its initial assignment. Using "val" helps to create more predictable and maintainable code by limiting the scope for errors caused by unintended variable reassignments.
This code example demonstrates how to use "val" to declare an immutable list of Person objects. The list is iterated over, and each person's name and age are printed. Attempting to reassign the "people" variable would result in a compilation error, as "val" ensures it is read-only.
En esta página del sitio puede ver el video en línea Write Safer Code with Kotlin's Immutable Variables: Using "val" de Duración hora minuto segunda en buena calidad , que subió el usuario Donutloop 01 abril 2023, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 105 veces y le gustó 1 a los espectadores. Disfruta viendo!