我有需要按2个参数排序的项目列表,第一个参数是orderIndex,我有那个部分正常工作(参见下面的代码),orderIndex之后的第二个参数是金额.因此,基本上第一项应该是订单索引最低的项目,并且需要按金额进行排序.
result.stream().sorted { s1, s2 -> s1.intervalType.orderIndex.compareTo(s2.intervalType.orderIndex) }.collect(Collectors.toList())
此时我有那个代码,它只是按orderIndex排序,第二个参数金额位于s1.item.amount.
知道如何使用第二个排序参数升级此代码吗?
我找到了这个例子
persons.stream().sorted(Comparator.comparing(Person::getName).thenComparing(Person::getAge));
我的问题是,如何访问Person中的其他对象,例如在我的情况下,我在对象中有IntervalType对象,我正在排序,我需要使用intervalType.orderIndex
注意:
只是为了注意我需要在Kotlin而不是Java中.