Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Documentation says "default operator == implementation only considers objects equal if they are identical",why isnt it applied here?

    void main(){
    String characters='World';
    String a='Hello $characters';
    String b='Hello $characters';
    print(a==b); 

outputs true

    print(identical(a,b));

outputs false on VS code but true on dartPad,I cant understand

    }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The == operator tests whether two objects are equivalent. Two strings are equivalent if they contain the same sequence of code units. See here.

The identical method from the dart:io library returns a Future that completes with the result. Comparing a link to its target returns false, as does comparing two links that point to the same target.

Do you import this method from the dart:io library in VS Code? If so, then it interprets your strings as a path to an object, which then returns false (as marked above).

If so, consider changing the import to dart:core library to simply check with identical() whether two references are to the same object.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading