operator == method

  1. @override
bool operator ==(
  1. Object other
)
override

== see: https://www.dartlang.org/docs/dart-up-and-running/contents/ch02.html#op-equality

To test whether two objects x and y represent the same thing, use the == operator.

(In the rare case where you need to know whether two objects are the exact same object, use the identical() function instead.)

Here is how the == operator works:

If x or y is null, return true if both are null, and false if only one is null.

Return the result of the method invocation x.==(y).

Evolution:

If x===y, return true. Otherwise, if either x or y is null, return false. Otherwise, return the result of x.equals(y).

The newer spec is: a) if either x or y is null, do identical(x, y) b) otherwise call operator ==

Read: http://work.j832.com/2014/05/equality-and-dart.html http://stackoverflow.com/questions/29567322/how-does-a-set-determine-that-two-objects-are-equal-in-dart

Implementation

@override
bool operator ==(Object other) {
  if (other is Entity) {
    Entity entity = other;
    if (identical(this, entity)) {
      return true;
    } else {
      return equals(entity as E);
    }
  } else {
    return false;
  }
}