void main(){
int a=3;
int b=3;
print(identical(a,b));
returns true
double c=3.2;
double d=3.2;
print(identical(c,d));
returns true, same for String type
List l1=[1,2,3];
List l2=[1,2,3];
print(identical(l1,l2));
}
But for list returns false.How?.As int,double,string override ==operator does that have anything to do with identical returning true for these types.
bool
,int
,double
, andString
are all immutable, so Dart can canonicalize their literals as an optimization without affecting behavior (other thanidentical
itself). The same cannot be said forList
,Map
, orSet
literals since they are mutable. Two separate[1, 2, 3]
literals cannot be canonicalized since mutating one should not affect the other.