【发布时间】:2020-05-11 07:47:44
【问题描述】:
我想要一个可以按属性排序的类(可能使用 Comparable 和 Comparator)。但是这个类不是一个普通的类属性,而是一个“键值对列表”。
class Normal
{
String attrib1;
String attrib2;
int attrib3;
}
这个类的属性
class Special
{
Map<String,Object> attributes =new HashMap<String,Object>()
}
基本上,类属性是根据场景动态生成的。所以在给定的场景中,对象属性 hashmap 会有,
attrib1 : "value1"
attrib2 : "value2"
attrib3 : 3
所以我需要实现“Special”类,其中“Special”类型的对象列表可以按给定的属性排序(等:按属性3排序)。
【问题讨论】:
标签: java sorting generics comparator comparable