- Functional Kotlin
- Mario Arias Rivu Chakraborty
- 55字
- 2021-06-24 19:15:23
Checking for null
Check for null as a condition in the if block:
fun main(args: Array<String>) {
val nullableCupcake: Cupcake? = Cupcake.almond()
if (nullableCupcake != null) {
nullableCupcake.eat()
}
}
Kotlin will do a smart cast. Inside the if block, nullableCupcake is a Cupcake, not a Cupcake?; so, any method or property can be accessed.
推薦閱讀
- Instant Node Package Manager
- Bootstrap Site Blueprints Volume II
- Qt 5 and OpenCV 4 Computer Vision Projects
- 軟件項目管理(第2版)
- Visual Basic 6.0程序設計計算機組裝與維修
- Building a Home Security System with Raspberry Pi
- Python爬蟲開發:從入門到實戰(微課版)
- Ext JS Data-driven Application Design
- OpenNI Cookbook
- 名師講壇:Java微服務架構實戰(SpringBoot+SpringCloud+Docker+RabbitMQ)
- 精通網絡視頻核心開發技術
- JAVA程序設計實驗教程
- Python編程從0到1(視頻教學版)
- Mastering Unity 2D Game Development(Second Edition)
- Red Hat Enterprise Linux Troubleshooting Guide