Another one: I have defined a field `val liveChall...
# announcements
m
Another one: I have defined a field
val liveChallenge = MutableLiveData<Challenge>()
. I want to expose it as a
LiveData<Challenge>
. Should I just make the field private and write a getter,
fun getLiveChallenge(): LiveData<Challenge> = liveChallenge
(like I would do in Java) or is there a smarter way?
d
Make a private property and a public one with custom getter:
Copy code
private val liveChallengeMutable = MutableLiveData<Challenge>()
val liveChallenge: LiveData<Challenge> get() = liveChallengeMutable
g
Unfortunately there is no better way, except using properties instead of method (better for consumer, but same ammount of code)
Vote and add your use case to this feature 👍 https://youtrack.jetbrains.com/issue/KT-14663
m
Alright. Thanks 🙂