- Functional Kotlin
- Mario Arias Rivu Chakraborty
- 73字
- 2021-06-24 19:15:23
The (!!) operator
Instead of a null value, the !! operator will throw an NPE:
val result: String = nullableCupcake!!.eat()
If you can deal with an NPE, the !! operator gives you a pretty convenient feature, a free smart cast:
val result: String = nullableCupcake!!.eat()
val length: Int = nullableCupcake.eat().length
If nullableCupcake!!.eat() doesn't throw an NPE, Kotlin will change its type from Cupcake? to Cupcake from the next line and onwards.
推薦閱讀
- Learn ECMAScript(Second Edition)
- VMware View Security Essentials
- Python數據分析基礎
- C# 2012程序設計實踐教程 (清華電腦學堂)
- Java EE 7 Performance Tuning and Optimization
- 劍指大數據:企業級數據倉庫項目實戰(在線教育版)
- CoffeeScript Application Development Cookbook
- Java程序設計案例教程
- C專家編程
- Mastering AWS Security
- Java7程序設計入門經典
- HTML5與CSS3權威指南
- JavaWeb從入門到精通(視頻實戰版)
- Python計算機視覺與深度學習實戰
- Bitcoin Essentials