https://kotlinlang.org logo
v

vineethraj49

01/24/2021, 10:00 PM
hi, quick question; what's the difference between
Copy code
val foo
  get() = expensiveOrAllocFunc()
vs
Copy code
val foo by lazy { expensiveOrAllocFunc() }
d

diesieben07

01/24/2021, 10:04 PM
The first one calls the function every time you get
foo
. The 2nd one computes it only on first access and then keeps the same result.
🙏 2
👍 3
3 Views