is there a way to accomplish something like this w...
# announcements
b
is there a way to accomplish something like this without the need for a temp variable?
Copy code
val temp = someMember
someMember = null
temp.close()
i've got multiple threads accessing
someMember
(via
?.
), want to make sure it isn't accessed in between calling
close()
and assigning it to null.
m
Copy code
someMember.also {
    someMember = null
    it.close()
}
b
great, thanks. after looking at that, i think
?.let
will work even better.
m
I would recommend
?.also
as you don’t calculate a new value based on
someMember
, but thats just preference.
b
true, you're right, i don't need the return
m
You could even remove one line more 😄:
Copy code
someMember?.also {
    someMember = null
}?.close()
b
ha, nice