compareObjectTo method
-
If this object and
other
are bothnull
, they don't have order. If one of them isnull
, it will come later, unless thenullsBefore
istrue
, in which case thenull
will come before. -
Otherwise, if this object and
other
are both of type Comparable, compare them with their natural comparator. -
Otherwise, if this object and
other
are map-entries (MapEntry
), compare theirkey
s. If theirkey
s compare as the same, then compare theirvalue
s. -
Otherwise, if this object and
other
are booleans, compare them such astrue
comes afterfalse
. -
Otherwise, return
0
, which means unordered.
Examples:
5.compareObjectTo(2);
true.compareObjectTo(false);
MapEntry('a', 5).compareObjectTo(MapEntry('b', 3));
Example with null
s coming before:
5.compareObjectTo(2, nullsBefore: true);
Implementation
int compareObjectTo(
Object? other, {
bool nullsBefore = false,
bool compareHashCodes = true,
}) =>
compareObject(this, other, nullsBefore: nullsBefore);