, min, max sorted Stream, , , Java , .
, , sorted()?
, , . Generics , Comparator . , , , . , , . , , , .
Arrays.sort(Object[]) Comparable. ,sort(T[] a, Comparator<? super T> c) , null " ",Collections.sort(List<T> list) ,Collections.sort(List<T> list, Comparator<? super T> c) , null " ", theres . "null " , Generics, .
. List.sort(Comparator), Java 8, null " ", , , , , .
, , . Stream.sorted(Comparator) - , null. Comparator.naturalOrder() sorted() . , null sorted() - , Stream , , Comparator.naturalOrder().
As a rule, the safety of comparator types is low. For example. Collections.reverseOrder()returns a comparator of an arbitrary type without requiring a comparable type. Therefore, instead, min()you can use max(Collections.reverseOrder())to query for a minimum regardless of the formal type of threads. Or use Collections.reverseOrder(Collections.reverseOrder())to get the equivalent Comparator.naturalOrder()for an arbitrary type. Similarly, it Collatorimplements Comparator<Object>, for some reason, despite the fact that it can only compare Strings.