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

(coll) Collections.EmptyList could override iterator for improved performance

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6
    • core-libs

      The private class EmptyList of java.util.Collections could override iterator
      and perhaps improve performance of the enhanced for loop.

      Simply add this to the class:

      private static Iterator<?> iterator = new Iterator() {
          public boolean hasNext() { return false; }
          public Object next() { throw new NoSuchElementException(); }
          public void remove() { throw new UnsupportedOperationException(); }
      }
      public Iterator iterator() { return iterator; }

            martin Martin Buchholz
            ahe Peter Ahe
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: