Tuesday, July 12, 2011

Scala's result type "Unit"

A result type of Unit indicates the function returns no interesting
value. Scala’s Unit type is similar to Java’s void type, and in fact every
void-returning method in Java is mapped to a Unit-returning method in
Scala.

def test(args: Array[String]): Unit = {
var i = 0
while (i < args.length) {
println(args(i))
i += 1
}
}

No comments: