July 2018
Intermediate to advanced
242 pages
8h 6m
English
We are delegating the var temperature variable to the result of the Delegates.observable() function, which returns an instance of the ReadWriteProperty class. That fact makes it possible to declare temperature as a mutable variable. The observe() function takes two arguments—the initial value, and an instance of the hook function that is going to be invoked on every change made to the delegated variable. In our case, we are instantiating the function as the lambda block, which is supposed to print the new temperature value to the console.
Let's test how our implementation is going to work. We are going to modify the value of the temperature directly a couple of times:
temperature = 10temperature = 11temperature = 12temperature ...
Read now
Unlock full access