- Functional Kotlin
- Mario Arias Rivu Chakraborty
- 62字
- 2021-06-24 19:15:23
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
推薦閱讀
- The Complete Rust Programming Reference Guide
- C++ Builder 6.0下OpenGL編程技術
- Windows系統(tǒng)管理與服務配置
- Mastering macOS Programming
- SSM輕量級框架應用實戰(zhàn)
- PhoneGap:Beginner's Guide(Third Edition)
- Learning Three.js:The JavaScript 3D Library for WebGL
- Scratch3.0趣味編程動手玩:比賽訓練營
- Hands-On Neural Network Programming with C#
- Building Serverless Web Applications
- 計算機應用基礎項目化教程
- Learning Cocos2d-JS Game Development
- 關系數據庫與SQL Server 2012(第3版)
- JavaWeb從入門到精通(視頻實戰(zhàn)版)
- Visual C++程序開發(fā)范例寶典