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

The Elvis (?:) operator

The Elvis operator (?:) returns an alternative value if a null value is used in an expression:

val result2: String = nullableCupcake?.eat() ?: ""

If nullabluCupcake?.eat() is null, the ?: operator will return the alternative value "".

Obviously, the Elvis operator can be used with a chain of safe calls:

val length2: Int = nullableCupcake?.eat()?.length ?: 0
主站蜘蛛池模板: 吉隆县| 怀宁县| 新营市| 平南县| 兴安县| 贺州市| 开封县| 枣阳市| 淮滨县| 逊克县| 怀安县| 白沙| 体育| 昔阳县| 天气| 吉木萨尔县| 建瓯市| 枞阳县| 安泽县| 呼图壁县| 密山市| 宝兴县| 中西区| 石狮市| 周口市| 眉山市| 虎林市| 革吉县| 罗城| 陆河县| 宝应县| 郁南县| 彩票| 巴中市| 塔城市| 济宁市| 孙吴县| 小金县| 固阳县| 华容县| 黄大仙区|