官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 广河县| 黄龙县| 根河市| 塔城市| 桃园市| 万宁市| 奉新县| 淄博市| 盐源县| 那坡县| 饶河县| 兴和县| 大姚县| 江门市| 龙游县| 三河市| 雅江县| 灵石县| 青川县| 南和县| 阜新| 邻水| 漳平市| 景宁| 高青县| 晋宁县| 丹阳市| 从江县| 扬中市| 星子县| 舟曲县| 容城县| 上饶县| 原阳县| 乌苏市| 屏边| 昆明市| 礼泉县| 和田县| 五家渠市| 新源县|