getx icon indicating copy to clipboard operation
getx copied to clipboard

fixed types in equality operator

Open ardakalayci opened this issue 1 year ago • 1 comments

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.

ardakalayci avatar Mar 05 '24 07:03 ardakalayci

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
}

jonataslaw avatar Mar 08 '24 17:03 jonataslaw