https://kotlinlang.org logo
#announcements
Title
# announcements
s

skennedy

08/17/2017, 9:30 PM
ugh i just got bit by the difference between
val X = blah()
and
Copy code
val X
  get() = blah()
😐 2
n

nayanjyoti

08/17/2017, 9:58 PM
@skennedy : Can u explain a bit?
s

skennedy

08/17/2017, 9:59 PM
the former calls
blah()
when the object is instantiated, the latter calls
blah()
every time you access the property
n

nayanjyoti

08/17/2017, 10:00 PM
Ouch !!
t

trevjones

08/17/2017, 10:11 PM
I tend to avoid synthetic properties for this exact reason.
c

codeslubber

08/17/2017, 10:46 PM
I would expect that though? although the usual preventative is ugly (that you see in swift too) of having a _ prefixed backing var…
t

trevjones

08/17/2017, 10:47 PM
yea it is expected, but prone to human error. thus my avoidance