https://kotlinlang.org logo
#getting-started
Title
# getting-started
b

Brian Donovan

09/15/2021, 6:43 PM
why am I getting this?
j

Joffrey

09/15/2021, 6:44 PM
You forgot
is
. You're getting this because the
when
is trying to compare expression values, it's not checking against types. So it's trying to get you to create a value of type
Resources.Success
by calling its constructor
b

Brian Donovan

09/15/2021, 6:44 PM
ty
j

Joffrey

09/15/2021, 6:47 PM
It depends on what you are doing. Your
when
branches can either check types or check values. You use
is
when you want to test whether the subject inside the
when
"is" of a certain type. If you don't use
is
, you're checking if the subject of the
when
is equal to the value in the branch.
When the expression in the branch is an
object
(probably the case of
Resource.Loading
), then an
is
check is kinda the same as a value check, because there is only one value of this type
b

Brian Donovan

09/15/2021, 6:49 PM
wow thats a lot, thanks. I will diff have to look more into it
2 Views