Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8030848

Collections.sort(List l, Comparator) should defer to List.sort(Comparator )

    Details

      Backports

        Description

        The implementation of the method Collections.sort(List l, Comparator) should be implemented as follows:

            @SuppressWarnings({"unchecked", "rawtypes"})
            public static <T> void sort(List<T> list, Comparator<? super T> c) {
                list.sort(c);
            }

        and the default implementation in List.sort should be the previous implementation of Collectors.sort:

            default void sort(Comparator<? super E> c) {
                Object[] a = toArray();
                Arrays.sort(a, (Comparator)c);
                ListIterator<E> i = listIterator();
                for (Object e : a) {
                    i.next();
                    i.set((E) e);
                }
            }

        Thus ensuring that Collection.sort will use the most optimal sort implementation provided by the list implementation.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  psandoz Paul Sandoz
                  Reporter:
                  psandoz Paul Sandoz
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  6 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: