Kotlin - Variables and Type System
You want to create a list of user names that should never change after creation. Which Kotlin declaration is best and why?
val users = listOf("Anna", "Bob", "Cara")val users = listOf("Anna", "Bob", "Cara")val means the reference cannot change, and listOf creates an immutable list that cannot be modified.val with listOf because it creates an immutable list and reference. uses val and listOf, ensuring both the reference and list contents cannot change, which matches the requirement.val with listOf because it creates an immutable list and reference. -> Option A15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions