Answer the question
In order to leave comments, you need to log in
How does safe call work in Kotlin?
Hey!
Let's take an example:
val map = HashMap<String, String>()
val str = map["str"]?.trim()?.toLowerCase()
Answer the question
In order to leave comments, you need to log in
No, that's not how it works.
The result of the expression x?.f() is nullable, and you want to call another function on it. Therefore, another "?" is needed: x?.f()?.g()
In what case can this be useful? The question is unclear, in any case.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question