I have a function that returns a live data such as...
# android
I have a function that returns a live data such as
Copy code
fun getLiveData(): LiveData<Result?> { return mResult }
where mResult is just a simple POJO. I am confused a bit about how kotlin interprets the return type for this function. I would imagine this to be non-null but when I try to call it, it forces me to use the null-safe operator "?.". If I wanted this to be nullable, I would imagine the return type would be
Copy code
with the appended "?"
From what I know, LiveData is made in Java, and is nullable by default or something like that. To provide you with more detailed information please check both: • https://chao2zhang.medium.com/livedata-nullability-99ef4e01bc54https://medium.com/google-developer-experts/when-livedata-and-kotlin-dont-play-hand-in-hand-30149aa794ec
👍 1
Thanks @Christiano
One thing that is interesting is that
in my example is always initialized to
when my app starts. It is never set to null. However, I am getting reports of crashes that indicate
is actually returning null.
What’s the exact exception you get?