java8 比较器

Collections.sort(annotationList,
        (o1,o2)->{
    return new Integer(((ExcelField)o1[0]).sort()).compareTo(
            new Integer(((ExcelField)o2[0]).sort())
    );
});


在JDK8 的编译环境下,形如上的代码会提示

 /**
         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[]> 应该 怎么写呢?

这个暂时还没想出来。

如果你知道,请评论下,非常感谢。




posted @ 2018-04-18 21:37  方家小白  阅读(32)  评论(0)    收藏  举报