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

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)
主站蜘蛛池模板: 安吉县| 光泽县| 马公市| 曲周县| 明星| 安多县| 九寨沟县| 永胜县| 洛浦县| 视频| 上林县| 乌兰县| 嵩明县| 昌黎县| 兴国县| 叶城县| 慈溪市| 遂平县| 黑山县| 伊金霍洛旗| 葫芦岛市| 宁化县| 德兴市| 定陶县| 济南市| 阿克陶县| 沭阳县| 剑川县| 陈巴尔虎旗| 松溪县| 丹阳市| 永安市| 巴林右旗| 临安市| 通渭县| 凤阳县| 科技| 九龙城区| 泰来县| 饶平县| 葫芦岛市|