复制代码
1
2
3
4
5
6
7Collections.sort(annotationList, (o1,o2)->{ return new Integer(((ExcelField)o1[0]).sort()).compareTo( new Integer(((ExcelField)o2[0]).sort()) ); });
在JDK8 的编译环境下,形如上的代码会提示
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15/** Reports Comparators defined as lambda expressions which could be expressed using methods like Comparator.comparing(). Some comparators like (person1, person2) -> person1.getName().compareTo(person2.getName()) could be simplified like this: Comparator.comparing(Person::getName). Also suggests to replace chain comparisons with Comparator.thenComparing(), e.g. int res = o1.first.compareTo(o2.first); if(res == 0) res = o1.second.compareTo(o2.second); if(res == 0) res = o1.third - o2.third; return res; will be replaced with objs.sort(Comparator.comparing((Obj o) -> o.first).thenComparing(o -> o.second).thenComparingInt(o -> o.third)); */
一般的对象还好说,但是当List<Object[]> 应该 怎么写呢?
这个暂时还没想出来。
如果你知道,请评论下,非常感谢。
最后
以上就是哭泣大炮最近收集整理的关于java8 比较器的全部内容,更多相关java8内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复