August 2017
Intermediate to advanced
440 pages
10h
English
The safe call operator is simply a question mark followed by a dot. It's important to understand that the safe cast operator will always return a value. If the left-hand side of the operator is null, then it will return null, otherwise it will return the result of the right-hand side expression:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val locked: Boolean? = savedInstanceState?.getBoolean("locked")
}
If savedInstanceState is null, then null will be returned, otherwise the result of evaluating a savedInstanceState?.getBoolean("locked") expression will be returned. Keep in mind that a nullable reference call always returns nullable, so the result of the whole expression is a nullable ...
Read now
Unlock full access