- 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.
推薦閱讀
- 數據科學實戰手冊(R+Python)
- Getting Started with Gulp(Second Edition)
- Java編程指南:基礎知識、類庫應用及案例設計
- 從學徒到高手:汽車電路識圖、故障檢測與維修技能全圖解
- Kotlin編程實戰:創建優雅、富于表現力和高性能的JVM與Android應用程序
- Learning PHP 7
- Visual Basic程序設計習題與上機實踐
- ExtJS Web應用程序開發指南第2版
- 動手打造深度學習框架
- Lift Application Development Cookbook
- Modular Programming with JavaScript
- C語言程序設計
- Python編程:從入門到實踐(第2版)
- 零基礎學西門子PLC編程:入門、提高、應用、實例
- Instant MongoDB