https://kotlinlang.org logo
#compose
Title
# compose
m

Mehdi Haghgoo

11/13/2020, 4:55 AM
I cannot seem to understand these two lines in the state code lab. private var _todoItems = MutableLiveData(listOf<TodoItem>()) val todoItems: LiveData<List<TodoItem>> = _todoItems If todoItems is immutable val, then how is it constantly updated with _todoItems livedata?
r

romainguy

11/13/2020, 5:16 AM
Think in Java if you wrote List<String> l = new ArrayList<String>()
m

Mehdi Haghgoo

11/13/2020, 5:40 AM
So, todoItems is not really immutable, is it?
g

gildor

11/13/2020, 6:31 AM
yes, it’s correct, they are read only,
i

Ian Lake

11/13/2020, 6:42 AM
The
todoItems
variable always points to the same object in memory (the
LiveData
object), that's what
val
means.
val
says nothing about the mutability of the object itself
❤️ 2