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

Return singleton empty list if zero copies requested in Collections::nCopies

    XMLWordPrintable

Details

    Description

      A DESCRIPTION OF THE PROBLEM :
      There exists in the Collections class a method called "nCopies". Optimize this method to return Collections.emptyList() if n equals 0 to avoid instantiating an empty CopiesList object.

          public static <T> List<T> nCopies(int n, T o) {
              if (n < 0)
                  throw new IllegalArgumentException("List length = " + n);
              return new CopiesList<>(n, o);
          }


      Attachments

        Activity

          People

            smarks Stuart Marks
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: