compareTo method

int compareTo(
  1. dynamic other
)

比较两个值

Implementation

int compareTo(dynamic other) {
  if (this == null && other == null) return 0;
  if (this == null) return -1;
  if (other == null) return 1;
  if (this is num && other is num) return (this as num).compareTo(other);
  if (this is BigInt && other is BigInt) return (this as BigInt).compareTo(other);
  if (this is String && other is String) return (this as String).compareTo(other);
  if (this is DateTime && other is DateTime) return (this as DateTime).compareTo(other);
  if (this is Duration && other is Duration) return (this as Duration).compareTo(other);
  // 其他情况,比对字符串
  return toString().compareTo(other.toString());
}