Skip to content

Instantly share code, notes, and snippets.

@miyoyo
Created September 11, 2018 09:56
Show Gist options
  • Save miyoyo/01d29cdc6e41178583ef5b134a09ba9c to your computer and use it in GitHub Desktop.
Save miyoyo/01d29cdc6e41178583ef5b134a09ba9c to your computer and use it in GitHub Desktop.
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