operator == method

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

Determines whether this Quantity is equal to another Object.

Two Quantity instances are considered equal if they are:

  1. The same instance (identical).
  2. Of the exact same runtime type (e.g., both Length, not one Length and one Pressure).
  3. Have the same numerical value.
  4. Have the same unit.

This means 1.m is NOT equal to 100.cm according to ==, because their units differ, even though their physical magnitudes are the same. For magnitude comparison, use compareTo() or convert to a common unit first.

  • other: The object to compare against.

Returns true if the objects are equal based on the criteria above, false otherwise.

Implementation

@override
bool operator ==(Object other) {
  if (identical(this, other)) return true;
  return other is Quantity<T> &&
      runtimeType == other.runtimeType &&
      _value == other._value &&
      _unit == other._unit;
}