- Functional Kotlin
- Mario Arias Rivu Chakraborty
- 85字
- 2021-06-24 19:15:23
Safe calls
Safe calls let you access methods and properties of nullable values if the value isn't null (under the hood, at the bytecode level, a safe call is transformed into if(x != null)):
nullableCupcake?.eat()
But, what if you use it in an expression?
val result: String? = nullableCupcake?.eat()
It will return null if our value is null, so result must have a String? type.
That opens up the chance to use safe calls on a chain, as follows:
val length: Int? = nullableCupcake?.eat()?.length
推薦閱讀
- Learning ROS for Robotics Programming(Second Edition)
- Python量化投資指南:基礎(chǔ)、數(shù)據(jù)與實(shí)戰(zhàn)
- 信息安全技術(shù)
- Mastering JBoss Enterprise Application Platform 7
- 微信小程序入門指南
- 零基礎(chǔ)入門學(xué)習(xí)Python(第2版)
- 青少年信息學(xué)競(jìng)賽
- Visualforce Developer’s guide
- Couchbase Essentials
- Java EE企業(yè)級(jí)應(yīng)用開(kāi)發(fā)教程(Spring+Spring MVC+MyBatis)
- Azure Serverless Computing Cookbook
- 代替VBA!用Python輕松實(shí)現(xiàn)Excel編程
- 超簡(jiǎn)單:Photoshop+JavaScript+Python智能修圖與圖像自動(dòng)化處理
- React and React Native
- Instant AppFog