- 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
推薦閱讀
- WebAssembly實戰
- 我的第一本算法書
- Python Tools for Visual Studio
- HTML5+CSS3網站設計教程
- Blender 3D Incredible Machines
- Windows Forensics Cookbook
- Instant Ext.NET Application Development
- PHP+MySQL+Dreamweaver動態網站開發從入門到精通(第3版)
- NoSQL數據庫原理
- 基于ARM Cortex-M4F內核的MSP432 MCU開發實踐
- C# Multithreaded and Parallel Programming
- IDA Pro權威指南(第2版)
- Learning iOS Security
- 測試架構師修煉之道:從測試工程師到測試架構師
- QlikView Unlocked