myString?.let{ mTextview.text = myString }
# android
o
myString?.let{ mTextview.text = myString }
v
Yup. Anyways, did not you get any warning or compile time error when you called let on a nullable object?
m
let
is defined for all objects. Even nullable ones.
j
you can also write `it`inside of the let
t
or you can use
apply
and it’ll as simple as
text=..
m
Do you mean
mTextview.apply { text = myString }
@tokajip ? In that case, you lose the null-check on
myString
.
t
Yes, but I mean
mTextView?.apply { text = myString }
you’ll have null-check on
myString
and save the
myString
or
it
inside the function
m
Now you have the nullcheck on
mTextView
which isn't nullable.
myString
can still be null.
t
Ohh, my mistake. I thought in the original post it was
TextView
on called
?.let{ }
but as I looked again, I saw its a
String
But on Android you can set null for a
TextView
text
property, because the system’ll transform it to an empty
String
👍 1
m
Yep, but he might want to keep the old text when
myString
is null.