- 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.
推薦閱讀
- PaaS程序設(shè)計(jì)
- 認(rèn)識(shí)編程:以Python語(yǔ)言講透編程的本質(zhì)
- 樂(lè)高機(jī)器人設(shè)計(jì)技巧:EV3結(jié)構(gòu)設(shè)計(jì)與編程指導(dǎo)
- Responsive Web Design with HTML5 and CSS3
- C語(yǔ)言程序設(shè)計(jì)
- C語(yǔ)言開(kāi)發(fā)基礎(chǔ)教程(Dev-C++)(第2版)
- Learning Concurrency in Kotlin
- Java EE企業(yè)級(jí)應(yīng)用開(kāi)發(fā)教程(Spring+Spring MVC+MyBatis)
- Python機(jī)器學(xué)習(xí)之金融風(fēng)險(xiǎn)管理
- Buildbox 2.x Game Development
- Python大學(xué)實(shí)用教程
- 大學(xué)計(jì)算機(jī)基礎(chǔ)
- ASP.NET求職寶典
- Oracle Database XE 11gR2 Jump Start Guide
- Spring Web Services 2 Cookbook