September 2018
Intermediate to advanced
398 pages
9h 43m
English
In Scala, a variable can be declared using val or var. A val is immutable, which means you can never change its value. A var is mutable. It is not mandatory to declare the type of the variable. If you do not declare it, Scala will infer it for you.
Let's define some immutable variables:
scala> val x = 1 + 1x: Int = 2scala> val y: Int = 1 + 1y: Int = 2
In both cases, the type of the variable is Int. The type of x was inferred by the compiler to be Int. The type of y was explicitly ...
Read now
Unlock full access