https://kotlinlang.org logo
Title
m

matt tighe

05/15/2019, 9:21 PM
when passing objects as parameters to constructors, are those objects kept as references in the class being constructed, or are they released once construction is complete? eg
class MyClass(instance: MyObject) {
    val prop = instance.myFun()   
}
would
instance
be released as soon as construction had completed?
additionally, what if
prop
were lazily instantiated?
d

Dominaezzz

05/15/2019, 9:23 PM
Then it would be captured I think.
k

karelpeeters

05/15/2019, 9:23 PM
"released", they're just constructor parameters, not actual fields.
m

matt tighe

05/15/2019, 9:23 PM
@karelpeeters sure, but an instance of
MyClass
would still need to be passed a reference to
instance
in order to compute
myFun()
, no?
k

karelpeeters

05/15/2019, 9:24 PM
Yes, but all that happens in the constructor.