good morning ! What the "!!" means ?
# android
f
good morning ! What the "!!" means ?
f
thanks!!!
s
? Means can be null and !! Means can't be null For example we have locations which can be null so we can write
Copy code
location?.let {
// do something if not null
Copy code
} ?: run {
// Do something if null
}
And
location!! // Is not null
@Fernando de Paula
u
location!! will produce crash if it is null it is only use when you are sure that property will not be null at a particular condition
k
!!
cast nullable object to non nullable object. If that object is null that operation will throw NullPointerException
s
@Umar Ata of course yes
f
very nice!
it is dangerous
u
try to avoid using !! and just use location?.let{ print(it.lat) } and this let will only trigger when location is not null
f
"it" is like "this" ?
s
It keyword will makes reference of location variable
k
it depends of method. let/run/apply etc…
n
Way of assuring that the value will not be null. This is to bypass the null check
g
I recommend #getting-started for such discussions, Android channel doesn’t look relevant to this
👍 1