Dart API Referencedart:coreComparable

Comparable abstract class

Interface used by types that have an intrinsic ordering.

abstract class Comparable {
  /**
   * Compares this object to another [Comparable]
   *
   * Returns a value like a [Comparator] when comparing [:this:] to [other].
   *
   * May throw an [ArgumentError] if [other] is of a type that
   * is not comparable to [:this:].
   */
  abstract int compareTo(Comparable other);

  /**
   * Compare one comparable to another.
   *
   * This utility function is used as the default comparator
   * for the [List] sort function.
   */
  static int compare(Comparable a, Comparable b) => a.compareTo(b);
}

Subclasses

Date, Duration, Level, String, intx, num

Static Methods

int compare(Comparable a, Comparable b) #

Compare one comparable to another.

This utility function is used as the default comparator for the List sort function.

static int compare(Comparable a, Comparable b) => a.compareTo(b);

Methods

abstract int compareTo(Comparable other) #

Compares this object to another Comparable

Returns a value like a Comparator when comparing this to other.

May throw an ArgumentError if other is of a type that is not comparable to this.