https://kotlinlang.org logo
s

Slackbot

06/03/2021, 8:41 AM
This message was deleted.
a

Apm29

06/03/2021, 8:54 AM
executed on created
v

Vivek Modi

06/03/2021, 8:57 AM
every time when we create SumInt object, function will store in memory? even we didn't call sumNumber
a

Apm29

06/03/2021, 8:58 AM
you can image that field sumNumber has a backfield, its value is computed on SumInt created by executing sum
v

Vivek Modi

06/03/2021, 9:00 AM
okk thanks
How to avoid this any suggestion?
a

Apm29

06/03/2021, 9:03 AM
did you want sum function called every time when you call get on sumNumber?
v

Vivek Modi

06/03/2021, 9:03 AM
yes i want only when i called sumNumber
k

knthmn

06/03/2021, 9:06 AM
if you want it to be calculated everytime
Copy code
val sumNumber get() = sum(firstNumber, secondNumber)
or if you want it to be calculated the first time it is accessed which the value is then stored
Copy code
val sumNumber by lazy { sum(firstNumber, secondNumber) }
v

Vivek Modi

06/03/2021, 9:07 AM
thanks a million 👍
a

Apm29

06/03/2021, 9:08 AM
👍
2 Views