Skip to content

Instantly share code, notes, and snippets.

@micimize
Last active January 10, 2020 17:49
Show Gist options
  • Save micimize/1cbfdd048ebc45f2e726f59f74712171 to your computer and use it in GitHub Desktop.
Save micimize/1cbfdd048ebc45f2e726f59f74712171 to your computer and use it in GitHub Desktop.
== asymmetry demo
class ThisClass {
int bar;
ThisClass(this.bar);
@override
bool operator ==(other) => other is ThisClass && other.bar == bar;
}
class ThatClass extends ThisClass {
ThatClass(int bar, this.bob) : super(bar);
int bob;
@override
bool operator ==(other) =>
other is ThatClass && other.bob == bob && super == (other);
}
// ...
void main() {
print(ThatClass(1, null) == ThisClass(1)); // false, good
print(ThisClass(1) == ThatClass(1, null)); // true, oops
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment