3 Variables

Variables are declared using the var keyword

In many cases, the type information can be omitted, thanks to Scala’s type inference

To declare a variable with explicit type, put the type after the variable name following a colon :

e.g.

var x: Int = 1 + 2
Tip: Adding explicit type is a matter of preference, in one hand it helps "documenting" your code, on the other hand it might make it more "cluttered". Use judgment, e.g. add explicit types to public interfaces and APIs, and skip it for internal implementation.

Code editor is using Scalakata.com written by Guillaume Massé