代码例子:
/*** 测试Comparator*/@Testpublic void test17() {//原始方法Comparator<Integer> comparator = new Comparator<Integer>() {@Overridepublic int compare(Integer o1, Integer o2) {return Integer.compare(o1, o2);}};int compare1 = comparator.compare(10, 11);System.out.println(compare1);System.out.println("********");//使用lambdaComparator<Integer> c2 = (o1, o2) -> Integer.compare(o1, o2);int compare2 = c2.compare(11, 10);System.out.println(compare2);System.out.println("********");//方法引用Comparator<Integer> c3 = Integer::compareTo;int compare3 = c3.compare(10, 11);System.out.println(compare3);}