- Kotlin Programming By Example
- Iyanu Adelekan
- 78字
- 2021-08-27 20:00:11
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.
推薦閱讀
- Learning Spring 5.0
- Manga Studio Ex 5 Cookbook
- Practical Internet of Things Security
- Data Analysis with Stata
- SQL Server 2012數據庫管理與開發項目教程
- Android 應用案例開發大全(第3版)
- C語言程序設計
- Microsoft Dynamics AX 2012 R3 Financial Management
- Mastering Python Design Patterns
- 人工智能算法(卷1):基礎算法
- QGIS 2 Cookbook
- Programming Microsoft Dynamics? NAV 2015
- Mastering jQuery Mobile
- Clojure Polymorphism
- Python大規模機器學習