- 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
推薦閱讀
- Facebook Application Development with Graph API Cookbook
- Java應(yīng)用與實戰(zhàn)
- Java Web開發(fā)之道
- Learn Programming in Python with Cody Jackson
- Mastering Drupal 8 Views
- BIM概論及Revit精講
- Visual Basic程序設(shè)計實驗指導(dǎo)(第二版)
- OpenMP核心技術(shù)指南
- 計算機應(yīng)用基礎(chǔ)(第二版)
- Laravel Design Patterns and Best Practices
- Test-Driven iOS Development with Swift
- 計算機應(yīng)用基礎(chǔ)(Windows 7+Office 2010)
- GO語言編程從入門到實踐
- Responsive Web Design with HTML5 and CSS3(Second Edition)
- GitHub Essentials