August 2017
Intermediate to advanced
440 pages
10h
English
Another tool to deal with nullable variables is the let function. This is actually not an operator, nor a language special construct. It is a function defined in the Kotlin standard library. Let's see the syntax of let combined with the safe call operator:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
savedInstanceState?.let {
println(it.getBoolean("isLocked")) // 1
}
}
As mentioned before, the right-hand expression of the safe call operator will be only evaluated if the left-hand side is not null. In this case, the right-hand side is a let function that takes another function (lambda) as a parameter. ...
Read now
Unlock full access