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

Ofir Bar

02/17/2020, 9:46 AM
for the first attempt (marked gray):
Copy code
Elvis operator always returns the left operand of non-nullable String
for the 2nd attempt (marked yellow):
Copy code
condition currentUser?.office?.name.toString() is always 'true'
Why is that not possible to be null?
k

Kiss Budai Matyas

02/17/2020, 9:48 AM
if you call .toString() on a null object, you will end up with a “null” as string and not
null
. You should have
…name?.toString()
👍 1
☝️ 1
🍻 1
o

Ofir Bar

02/17/2020, 9:48 AM
what the
,
does?
k

Kiss Budai Matyas

02/17/2020, 9:49 AM
oh, sorry, that should be a dot.
o

Ofir Bar

02/17/2020, 9:50 AM
Ohhhhh brilliant, thank you my friend 😄 issue fixed
What about when using formatted strings inside the strings.xml? For example, I use the following:
Copy code
<string name="main_profile_lawyer_title">עו"ד %1$s %2$s</string>
Copy code
fpTitleTextView.text = getString(R.string.main_profile_lawyer_title,currentUser?.firstName, currentUser?.lastName) ?: "SOME DEFAULT STRING"
The elvis for “SOME DEFAULT STRING” is grayed out.