Not sure if the terminology in the title is 100% correct, but what I mean is easily illustrated by this example:
class MyClass{
String str = '';
MyClass(this.str);
}
void main() {
MyClass obj1 = MyClass('obj1 initial');
print(obj1.str);
doSomething(obj1);
print(obj1.str);
doSomethingElse(obj1);
print(obj1.str);
}
void doSomething(MyClass obj){
obj.str = 'obj1 new string';
}
void doSomethingElse(MyClass obj){
obj = MyClass('obj1 new object');
}
This will print
obj1 initial
obj1 new string
obj1 new string
But what if I wanted doSomethingElse()
to actually modify what obj1
is referencing, so that the output would be:
obj1 initial
obj1 new string
obj1 new object
Is this possible in Dart, and if so, how?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…