来自 Kotlin 文档:
如果一个函数没有返回任何有用的值,它的返回类型是 Unit。Unit 是一种只有一个值的类型——Unit.VALUE。该值不必显式返回:
fun printHello(name : String?) : Unit {
if (name != null)
print("Hello, $name!")
else
print("Hi there!")
// We don't need to write 'return Unit.VALUE' or 'return', although we could
}
函数中返回单位的目的是什么?为什么 VALUE 在那里?这个价值是多少?