suppoze
10/24/2018, 9:01 AMval Foo = Bar()
and
val Foo
get() = Bar()
is that when using getter, the evaulation happens every time when accessing Foo
, right?robin
10/24/2018, 9:18 AMBar()
will be called immediately when the surrounding object is first created, and you're stuck with that particular instance of Bar
for the rest of the surrounding object's lifetime. In the second line, a new instance of Bar
is created everytime someone accesses Foo
, but no permanent reference to any Bar
will be kept around (at least inside this object).suppoze
10/24/2018, 9:30 AMchristophsturm
10/24/2018, 9:40 AMAndreas Sinz
10/24/2018, 9:49 AMrobin
10/24/2018, 9:57 AMBar()
has a side effect. If Bar
is just a simple data class, nothing happening there, so I'd say it's not that problematic.suppoze
10/24/2018, 10:39 AM