maxmello
01/23/2019, 9:56 AMwhen
. I have a field that holds an enum value and in another place, I have an (exhaustive) when given that field. So the parameter of the when
was of type T
. Then, I changed the field to be instead a LiveData<T>
. A lot of places in my source threw errors and I fixed them by calling .value
on the field. But the when
did not threw an error (as the when does not return anything, the fact that is is no longer exhausive is not an error). But why can I even write:
when(status /* type = LiveData<T>*/) {
T.FIRST_VALUE -> { ... }
T.SECOND_VALUE -> { ... }
T.THIRD_VALUE -> { ... }
as status can never be any of these types? When I try the same structure with a String as parameter, it throws an error (incompatible types).Dico
01/23/2019, 11:52 AMmaxmello
01/23/2019, 12:04 PMDico
01/23/2019, 12:05 PM