Piasy
03/16/2020, 1:34 PM?.
operator thread safe? for example I have a var str: String? = null
, is it safe to call str?.length
? could NPE happen?jw
03/16/2020, 1:37 PMval localStr = str
if (localStr != null) {
localStr.length
}
streetsofboston
03/16/2020, 1:37 PM?.
itself is ‘thread-safe’/‘atomic’.
But afer that call, the global/instance variable you called it on, can be null again.Piasy
03/16/2020, 1:40 PMAditya
03/16/2020, 5:45 PMlet
on that would resolve the thread safety issue, right?
My understanding is that
str?.let {
it.length
}
would be safe since the it
is a copyjw
03/16/2020, 5:50 PMstr?.length
Aditya
03/16/2020, 6:40 PMlet
made a local copy. Thanks!jw
03/16/2020, 6:46 PMstr?.length
. That was my point.