任何想法如何按其属性之一的字母顺序排序对象列表(不是名称,而是属性保存的实际值)?
谢谢!
我正在开发一个测量类,因此我想提供一个很好的 API 来比较两个测量值。
为了处理集合中的排序,我实现了Comparator. 对于一个很好的 API,我还实现了比较运算符<, <=, =>, >, ==。
所以我的类有以下方法:
bool operator <=(SELF other) => _value <= other._value;
bool operator <(SELF other) => _value < other._value;
bool operator >(SELF other) => _value > other._value;
bool operator >=(SELF other) => _value >= other._value;
@override
bool operator ==(Object other) =>
identical(this, other) || other is UnitValue && runtimeType == other.runtimeType && _value == other._value;
@override
int get hashCode => _value.hashCode;
int compareTo(SELF other) …Run Code Online (Sandbox Code Playgroud)