I'm having difficulty to understand Type of property when using delegated property. For example, from this Jetpack Compose documentation, it says both things are same.
1. val name: String by helloViewModel.name.observeAsState("")
2. val nameState: State<String> = helloViewModel.name.observeAsState("")
I've gone through the Kotlin Delegated property documentation here. For the first example, according to documentation, val name:String
, when we try to read this name
property, it will call getValue()
function on the delegate instance, whose return type would be String
, not State<String>
. But how come it is returning State<String
>, this part I didn't get completely.
Can you point me what I'm missing to understand this logic, or any link to documents/blog post would be great. Thanks