The Elvis operator

The Elvis operator is a terse structure that is present in Kotlin. It takes the following form:

(expression) ?: value2

Its usage in a Kotlin program is demonstrated in the following code block:

val nullName: String? = null
val firstName = nullName ?: "John"

If the value held by nullName is not null, the Elvis operator returns it, otherwise the "John" string is returned. Thus, firstName is assigned the value returned by the Elvis operator.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.20.231