Scala - Variable

Evaluation time

def example = 2      // evaluated when called
val example = 2      // evaluated immediately
lazy val example = 2 // evaluated once when needed

Immutable

Creating immutable variable is very simple and doesn't require any extra effort. “val” keyword does the trick.

val numbers = List(1,2,3,4)

Powered by ComboStrap