The Idioms section of the official Kotlin docs contains this example:
Builder-style usage of methods that return Unit
fun arrayOfMinusOnes(size: Int): IntArray { return IntArray(size).apply { fill(-1) } }
As the function apply
returns the generic type, and I thought Unit
is as same as void
in Java, this section is suggesting we can use a void method in builder-style? That doesn't make sense to me - what's it trying to say?