Any parameters to a method in Scala are vale, not vars.
Therefore, if you attempt to reassign a parameter inside a method in Scala, it won't compile.
The reason parameters are vals is that vals are easier to reason about. You needn't look further to determine if a val is reassigned, as you must do with a var.
In the absence of any explicit return statement, a Scala method returns the last value computed by the method.
Whenever you leave off the equals sign before the body of a function, its result type will definitely be Unit. Because the Scala compiler can convert any type to Unit.
No comments:
Post a Comment