https://kotlinlang.org logo
Title
f

Florian

10/17/2019, 8:08 AM
when I put an
init
block under a property I can initialize it there. This doesn't seem to work anymore if this property has a setter. Is that correct?
a

Alowaniak

10/17/2019, 8:22 AM
I'm guessing it's because in the setter the backing field (with the initial value) is available. The
init
block will call the setter. So in the setter the field will already need to be initialized.
f

Florian

10/17/2019, 8:24 AM
makes sense yea
so I guess I would set it to a default value instead
a

Alowaniak

10/17/2019, 8:25 AM
yea or an own private backing property perhaps (if you wish to bypass the setter in the
init
)