September 2018
Intermediate to advanced
398 pages
9h 43m
English
The following is a strict variable declaration:
class StrictDemo { val strictVal = { println("Evaluating strictVal") "Hello" } } val strictDemo = new StrictDemo //Evaluating strictVal //strictDemo: StrictDemo = StrictDemo@32fac009
We can see that println is called immediately. This means that the block at the right side of the assignment is evaluated as soon as the StrictDemo class is instantiated. If we want to delay the block's evaluation, we have to use the lazy prefix.
Read now
Unlock full access