when passing objects as parameters to constructors...
# getting-started
m
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
Copy code
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
Then it would be captured I think.
k
"released", they're just constructor parameters, not actual fields.
m
@karelpeeters sure, but an instance of
MyClass
would still need to be passed a reference to
instance
in order to compute
myFun()
, no?
k
Yes, but all that happens in the constructor.