Code B works well, but the Code A get the following warning prompt (It can run), why?
Enum argument can be null in Java, but exhaustive when contains no null branch
I think _playState.value can be null in Code B too, do I should add null branch when I use exhaustive when in Code B?
Code A
private val _selectAction = MutableLiveData<ESelect>()
val selectAction: LiveData<ESelect> = _selectAction
selectAction.observe(mLifecycleOwner) {
when(it) { //Enum argument can be null in Java, but exhaustive when contains no null branch
ESelect.SelectAll -> binding.chSelect.isChecked = true
ESelect.UnselectAll -> binding.chSelect.isChecked = false
ESelect.NoAction -> Unit
}
}
enum class ESelect{
SelectAll,
UnselectAll,
NoAction
}
Code B
private val _playState=MutableLiveData<EPlayState>()
override fun playOrPause(filename: String) {
when (_playState.value) {
EPlayState.STOPPED -> play(filename)
EPlayState.PLAYING -> pause()
EPlayState.PAUSED -> resume()
}
}
enum class EPlayState {
STOPPED,
PLAYING,
PAUSED
}