Created
September 11, 2018 09:56
-
-
Save miyoyo/01d29cdc6e41178583ef5b134a09ba9c to your computer and use it in GitHub Desktop.
This file contains 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
class Number { | |
int number; | |
Number(this.number); | |
} | |
void foo(Number n){ | |
n = Number(2); // Here you erase your reference and refer to a new Number | |
} | |
void bar(Number n){ | |
n.number = 3; // Here you mutate the "number" of the Number that was passed to you | |
} | |
void main(){ | |
var n = Number(1); | |
print(n.number); | |
foo(n); | |
print(n.number); | |
bar(n); | |
print(n.number); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment