Last active
January 10, 2020 17:49
-
-
Save micimize/1cbfdd048ebc45f2e726f59f74712171 to your computer and use it in GitHub Desktop.
== asymmetry demo
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 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