O'Reilly logo

Dart: Scalable Application Development by Ivo Balbaert, Sergey Akopkokhyants, Davy Mitchell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Comparing two objects

How can you determine whether two objects are equal or not? Basically, this is defined by objects (refer to the How it works… section of this recipe). Obviously, two equal objects will be of the same class (so the same type) and have the same value(s).

How to do it...

In the comparing_objects program, we define a class Person, override == and hashcode, and test the equality of some objects, as shown in the following code:

void main() { var p1 = new Person("Jane Wilkins", "485-56-7861", DateTime.parse("1973-05-08")); var p2 = new Person("Barack Obama", "432-94-1282", DateTime.parse("1961-08-04")); var p3 = p1; var p4 = new Person("Jane Wilkins", "485-56-7861", DateTime.parse("1973-05-08")); // with == and hashCode from Object: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required