How to determine which is better…..Lazy variable v...
# kotlin-native
r
How to determine which is better…..Lazy variable vs function with some return type…….. in kotlin. As we can use them interchangeably.
s
what are you trying to achieve?
s
Probably not the right channel to ask this question
r
@saket Could u plz tell me the right channel?
@Sourabh Rawat In a class where we have function with return type, that function can be converted into lazy variable. So, how to decide should we write lazy variable or function.
s
lazy block is run only once, but functions are run as many times they are called.
r
@Sourabh Rawat This helps. Thank u.
👍 1
h
Function is rather comparable to a value property with a custom getter. They basically do the same, one should choose between the two based on whether the action is rather accessing a property of the class or rather perform some kind of action/computation (--> function)
⬆️ 2
👍 2