- 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
推薦閱讀
- Redis Applied Design Patterns
- Boost C++ Application Development Cookbook(Second Edition)
- PHP程序設(shè)計(jì)(慕課版)
- RTC程序設(shè)計(jì):實(shí)時(shí)音視頻權(quán)威指南
- React.js Essentials
- Learn WebAssembly
- STM32F0實(shí)戰(zhàn):基于HAL庫(kù)開(kāi)發(fā)
- ASP.NET 3.5程序設(shè)計(jì)與項(xiàng)目實(shí)踐
- 表哥的Access入門:以Excel視角快速學(xué)習(xí)數(shù)據(jù)庫(kù)開(kāi)發(fā)(第2版)
- Web Development with MongoDB and Node(Third Edition)
- 動(dòng)手學(xué)數(shù)據(jù)結(jié)構(gòu)與算法
- Test-Driven JavaScript Development
- Android群英傳
- Python 3 數(shù)據(jù)分析與機(jī)器學(xué)習(xí)實(shí)戰(zhàn)
- 工業(yè)機(jī)器人離線編程