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

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.

主站蜘蛛池模板: 沙田区| 垫江县| 天气| 元阳县| 新闻| 纳雍县| 临朐县| 贡觉县| 句容市| 丽江市| 施秉县| 九江市| 同仁县| 蕲春县| 卢龙县| 新龙县| 桦南县| 鹿泉市| 纳雍县| 厦门市| 河东区| 巴中市| 三门峡市| 会昌县| 黄浦区| 军事| 河池市| 阜南县| 贡嘎县| 麦盖提县| 邢台县| 湖北省| 离岛区| 西乌珠穆沁旗| 平凉市| 如皋市| 彭阳县| 甘德县| 塔城市| 焉耆| 丰县|