官术网_书友最值得收藏!

  • 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)
主站蜘蛛池模板: 丰城市| 唐海县| 山东省| 丹东市| 抚顺市| 台南市| 烟台市| 旬阳县| 沂水县| 阿克陶县| 神木县| 麻江县| 元朗区| 东平县| 昆山市| 湖州市| 泽州县| 建阳市| 蒲城县| 武隆县| 杨浦区| 叶城县| 驻马店市| 德阳市| 浮梁县| 峨眉山市| 龙山县| 科技| 鄂尔多斯市| 昭觉县| 东乡族自治县| 新邵县| 防城港市| 十堰市| 东丰县| 图木舒克市| 呼图壁县| 驻马店市| 长治县| 台东市| 伊通|