I cannot seem to understand these two lines in the...
# compose
m
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
Think in Java if you wrote List<String> l = new ArrayList<String>()
m
So, todoItems is not really immutable, is it?
g
yes, it’s correct, they are read only,
i
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