new Comparator<T>(){ public int compare(...) {}}
, is a Comparator object so the()
is needed;Collections.sort()
:1
Line 3: error: no suitable method found for sort(int[][],<anonymous Comparator<int[]>>) Collections.sort(intervals, new Comparator<int[]>(){ ^ method Collections.<T#1>sort(List<T#1>) is not applicable (cannot infer type-variable(s) T#1 (actual and formal argument lists differ in length)) method Collections.<T#2>sort(List<T#2>,Comparator<? super T#2>) is not applicable (cannot infer type-variable(s) T#2 (argument mismatch; int[][] cannot be converted to List<T#2>)) where T#1,T#2 are type-variables: T#1 extends Comparable<? super T#1> declared in method <T#1>sort(List<T#1>) T#2 extends Object declared in method <T#2>sort(List<T#2>,Comparator<? super T#2>)
Collections.sort()
底层用的就是Arrays.sort()
, 两者底层都用的TimSort.sort()
;(见source code)
1 | public boolean canAttendMeetings(int[][] intervals) { |