- Functional Kotlin
- Mario Arias Rivu Chakraborty
- 107字
- 2021-06-24 19:15:24
The Unit type
Kotlin doesn't have methods with void return (as Java or C do). Instead, a method (or, to be precise, an expression) could have a Unit type.
A Unit type means that the expression is called for its side effects, rather than its return. The classic example of a Unit expression is println(), a method invoked just for its side effects.
Unit, like any other Kotlin type, extends from Any and could be nullable. Unit? looks strange and unnecessary, but is needed to keep consistency with the type system. Having a consistent type system have several advantages, including better compilation times and tooling:
anyMachine.process(Unit)
推薦閱讀
- Facebook Application Development with Graph API Cookbook
- 解構(gòu)產(chǎn)品經(jīng)理:互聯(lián)網(wǎng)產(chǎn)品策劃入門寶典
- 數(shù)據(jù)庫原理及應(yīng)用(Access版)第3版
- C語言程序設(shè)計實訓(xùn)教程
- Building Mapping Applications with QGIS
- 單片機(jī)應(yīng)用技術(shù)
- Linux命令行與shell腳本編程大全(第4版)
- INSTANT Yii 1.1 Application Development Starter
- Go語言入門經(jīng)典
- Mastering SciPy
- Java EE 8 and Angular
- Greenplum構(gòu)建實時數(shù)據(jù)倉庫實踐
- H5頁面設(shè)計與制作(全彩慕課版·第2版)
- Cinder:Begin Creative Coding
- 中小企業(yè)網(wǎng)站建設(shè)與管理(靜態(tài)篇)