June 2017
Intermediate to advanced
873 pages
18h 9m
English
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).
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: ...Read now
Unlock full access