# compose

Mehdi Haghgoo

09/02/2020, 8:46 AM
Copy code
private val todoViewModel by viewModels<TodoViewModel>()
Why can't we just write
val todoViewModel = List<TodoViewModel>()

Joost Klitsie

09/02/2020, 8:50 AM
Because the first one is using delegation to get a viewModel that is bound to the lifecycle of a certain component, like activity. You should check out the code what is in viewModels so you see what is actually happening under the hood
👍 2
the second thing you wrote creates a list of TodoViewModels, which is anyhow a different object (a view model vs a list of view models)
which doesn't even compile
or get you any viewmodels in the list