I am trying to follow the official Android guide for ViewModels in Kotlin. I literally copy pasted the easiest official example but the syntax seems to be illegal.
This section causes the problem:
private val users: MutableLiveData<List<User>> by lazy {
MutableLiveData().also {
loadUsers()
}
}
The preview gives me this error:
Property delegate must have a 'getValue(DashViewModel, KProperty*>)' method. None of the following functions is suitable.
And if I want to launch the App I get this error:
Type inference failed: Not enough information to infer parameter T in constructor MutableLiveData<T : Any!>()
Please specify it explicitly.
I dont understand those two errors and other questions with the same error seem to have been caused by something different. My guess is that the MutableLiveData().also
causes the problem but I do not know why. This is quite odd considering that this is an official example.