Hello everyone. ```class QueueExecutorImpl( pr...
# getting-started
f
Hello everyone.
Copy code
class QueueExecutorImpl(
    private val peripheral: Peripheral,
    parentScope: CoroutineScope,
) : QueueExecutor {
I have a simple doubt. In the above class I have two parameters: one with
private val
and another without any modifier. My doubt is the following:
peripheral
is a copy and parentScope is a reference for the external object??
h
No, everything is references. The
val
only makes the class keep it as a field (available after the constructor ends).
👍 1
f
Ok, if I use
val
and the reference is modified, the parameter of the class does not change because it is immutable, right? Otherwise, if
var
or none modifier is used the parameter changes if the reference is modified.
🚫 1
nono 1
s
"the reference is modified"
This is not a thing in Kotlin. You can't modify a reference.
f
I can not modify a reference, but I can modify its content, right? For example, it is possible cancel the scope of parentScope.
s
Sure, yes. But there's no implicit copying. Whether you store something in a
val
property, a
var
property, or just use it as a constructor parameter, you're still referencing the original object.
The difference between the two parameter styles in your example is the length of time the reference is held for; nothing else. No mutability or copying involved.
f
ok, you open my mind. thank you so much Sam
🐕 1