Last active
October 15, 2020 13:00
-
-
Save maheshj01/5aaab75669cd8279d5514c329ca077bc to your computer and use it in GitHub Desktop.
copying dart objects doesnt actually copy the contents of the object but gets a reference to it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
Foo t = Foo(); | |
t.a = ['a', 'b', 'c']; // some value | |
t.x = 30; | |
Foo t1 = t; | |
t1.a = ['x', 'y', 'z']; | |
t1.x = 20; | |
print(t1.a); // [x, y, z] | |
print(t.a); // [x, y, z] | |
print(t.x); | |
print(t1.x); | |
} | |
class Foo { | |
List<String> a = []; | |
int x = 10; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment