我正试着按照官方的Android指南在Kotlin中使用ViewModels. 我从字面上复制粘贴了最简单的official example个,但语法似乎是非法的.
这一部分导致了以下问题:
private val users: MutableLiveData<List<User>> by lazy {
MutableLiveData().also {
loadUsers()
}
}
预览显示以下错误:
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.
我不明白这两个错误和其他同样错误的问题似乎是由不同的原因造成的.我猜是MutableLiveData().also
导致了这个问题,但我不知道为什么.考虑到这是一个官方的例子,这很奇怪.