besides `lateinit`, all properties of a class need...
# getting-started
f
besides
lateinit
, all properties of a class need to be initialized when the object is constructed, right?
m
By something, yes.
lateinit
and
by lazy {}
are ways to supply the initial value later. Technically
by lazy {}
initializes the property up front, but with a property delegate, where the effective value is determined later by evaluating the lambda.
f
thanks
we can initialize them at declaration in the class body, inlined into the primary constructor, in the secondary constructor if there is no primary constructor and inside an init block
anything else?
m
Those are certainly the big ones. I cannot think of any other scenarios, but there are enough dusty corners of Kotlin syntax that there might be one that I'm forgetting. 😁
f
yea it's a little bit confusing for me
v
One thing is that people coming from Java might not consider a property having the value
null
as initialized but in Kotlin even a nullable property won't by default have the value of
null
. So initializing them with
null
would also count as initializing a property.
f
right thats a good point