I am learning sunflower app and came across this `...
# android
c
I am learning sunflower app and came across this
tabFragmentsCreators
variable https://github.com/android/sunflower/blob/master/app/src/main/java/com/google/samples/apps/sunflower/adapters/SunflowerPagerAdapter.kt#L32 What is the benefit of using a
Map<Int, () -> Fragment>
instead of just
Map<Int, Fragment>
a
Lazy creating fragment instance instead of keeping fragment instance in map (that's my understanding of it..)
c
Thanks, so it is just creating the fragments when it is "asked"(on-demand)?
a
Yeah
Copy code
() -> fragment
Will provide fragment when required
So instead of keeping instance of fragment mapped to int, we keep a function which gives an instance of fragment and map that to int
c
That makes sense. Thanks for your explanation👍
d
nice