Nullability and LiveData with Kotlin

前端 未结 8 1565
梦谈多话
梦谈多话 2021-02-19 02:57

I want to use LiveData with Kotlin and have values that should not be null. How do you deal with this? Perhaps a wrapper around LiveData? Searching for good patterns here .. As

8条回答
  •  说谎
    说谎 (楼主)
    2021-02-19 03:19

    When using strings is simple by using this way:

    val someLiveData = MutableLiveData()
    ...
    someLiveData.value.orEmpty()
    

    And you will get actual value if set or an empty string instead of null.

提交回复
热议问题