Hey guys, is it possible to reference the value pa...
# android
o
Hey guys, is it possible to reference the value passed to a
when
expression using something similar to
it
? In the code below “`it`” gets an error (
Unresolved reference: it
)
Copy code
when(mCurrentUserType){

UserType.HUMAN -> {
setViewForUserType(currentUser, it)
}

UserType.ANIMAL -> {
setViewForUserType(currentUser, it)
}

}
2
d
you can just use
mCurrentUserType
👍 1
BTW. don’t use hungarian notation in Kotlin
👍 3
o
@dawidhyzy I feel so stupid I want to delete the question lol But Is there a particular reason I can’t use
it
in this context? (Just to better understand my code) As for hungarian notation, why?
d
There is no
it
in context
If you have method call in when you can creat val. For example
Copy code
when (val response = executeRequest()) {
            is Success -> response.body
            is HttpError -> throw HttpException(response.status)
        }
because there is no benefit of hungarian notation
IDE marks properties
Kotlin creates getters/setters for properties So if you access them on Java you will see `getMCurrentUserType`/`setMCurrentUserType`
o
Got it, thanks man! @dawidhyzy
d
no worries
c
@dawidhyzy you are saying don’t use Hungarian then you are showing mixed case var names, which is hungarian? are you just saying don’t embed the type in the name?
d
Which one are you referring to? It was just an example of what he will see from Java if he use
m
prefix for properties.
👍 1
n
In Systems Hungarian notation, the prefix encodes the actual data type of the variable. ---Wikipedia Here,
mCurrentUserType
is following hungarian notation.