https://kotlinlang.org logo
#android
Title
# android
o

Ofir Bar

02/25/2020, 12:38 PM
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

dawidhyzy

02/25/2020, 1:06 PM
you can just use
mCurrentUserType
👍 1
BTW. don’t use hungarian notation in Kotlin
👍 3
o

Ofir Bar

02/25/2020, 1:17 PM
@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

dawidhyzy

02/25/2020, 1:24 PM
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

Ofir Bar

02/25/2020, 1:30 PM
Got it, thanks man! @dawidhyzy
d

dawidhyzy

02/25/2020, 1:30 PM
no worries
c

codeslubber

02/27/2020, 2:55 PM
@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

dawidhyzy

02/28/2020, 7:44 AM
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

Naveenkumar R

03/02/2020, 1:32 AM
In Systems Hungarian notation, the prefix encodes the actual data type of the variable. ---Wikipedia Here,
mCurrentUserType
is following hungarian notation.