Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed types in equality operator #3047

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ardakalayci
Copy link

When hashcode is not used, we can only be sure about whether primitive types have changed or not. However, for lists and maps, we need to check with hashcode.

@jonataslaw
Copy link
Owner

Can you explain this to me better?
The equality operator by default compares the hashCode of two objects.
A list will only be equal to another list if both are const. This doesn't seem to have anything to do with the hashcode.
Only immutable lists are the same as immutable lists.

void main() {
  
  List foo = [1,2,4, "eee"];
  List bar = [1,2,4, "eee"];
  
  print(foo == bar); // false
  print(foo.hashCode == bar.hashCode); // false
}
void main() {
  
  List foo = const  [1,2,4, "eee"];
  List bar = const [1,2,4, "eee"];
  
  print(foo == bar); // true
  print(foo.hashCode == bar.hashCode); // true
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants