July 2018
Intermediate to advanced
242 pages
8h 6m
English
Let's test out how the coffeeMaker instance is going to behave by running the following code:
val coffeMaker: CoffeeMaker by lazy { CoffeeMaker() }println("Is the CoffeMaker created already?")
coffeMaker.makeEspresso()coffeMaker.makeAmericano()
And here is the output printed out to the console:
Is the CoffeMaker created already?I'm being created right now... Ready to make some coffe!Un espresso, per favore!Un caffè americano, per favore!
As you might have imagined, the constructor of the CoffeeMaker class is being called only upon the first request to the coffeeMaker variable. In fact, the lambda block passed to the lazy function is invoked on the call to the coffeeMaker.makeEspresso() function. Once the CoffeeMaker object ...
Read now
Unlock full access