jdk/src/java.base/share/classes/java/util/List.java
changeset 39568 1987f3929c39
parent 38567 6d4c5a278fff
child 40788 01ffe34b7340
equal deleted inserted replaced
39567:43cbd4fc502b 39568:1987f3929c39
   739      * {@link Spliterator#ORDERED}.  Implementations should document the
   739      * {@link Spliterator#ORDERED}.  Implementations should document the
   740      * reporting of additional characteristic values.
   740      * reporting of additional characteristic values.
   741      *
   741      *
   742      * @implSpec
   742      * @implSpec
   743      * The default implementation creates a
   743      * The default implementation creates a
   744      * <em><a href="Spliterator.html#binding">late-binding</a></em> spliterator
   744      * <em><a href="Spliterator.html#binding">late-binding</a></em>
   745      * from the list's {@code Iterator}.  The spliterator inherits the
   745      * spliterator as follows:
   746      * <em>fail-fast</em> properties of the list's iterator.
   746      * <ul>
       
   747      * <li>If the list is an instance of {@link RandomAccess} then the default
       
   748      *     implementation creates a spliterator that traverses elements by
       
   749      *     invoking the method {@link List#get}.  If such invocation results or
       
   750      *     would result in an {@code IndexOutOfBoundsException} then the
       
   751      *     spliterator will <em>fail-fast</em> and throw a
       
   752      *     {@code ConcurrentModificationException}.
       
   753      *     If the list is also an instance of {@link AbstractList} then the
       
   754      *     spliterator will use the list's {@link AbstractList#modCount modCount}
       
   755      *     field to provide additional <em>fail-fast</em> behavior.
       
   756      * <li>Otherwise, the default implementation creates a spliterator from the
       
   757      *     list's {@code Iterator}.  The spliterator inherits the
       
   758      *     <em>fail-fast</em> of the list's iterator.
       
   759      * </ul>
   747      *
   760      *
   748      * @implNote
   761      * @implNote
   749      * The created {@code Spliterator} additionally reports
   762      * The created {@code Spliterator} additionally reports
   750      * {@link Spliterator#SUBSIZED}.
   763      * {@link Spliterator#SUBSIZED}.
   751      *
   764      *
   752      * @return a {@code Spliterator} over the elements in this list
   765      * @return a {@code Spliterator} over the elements in this list
   753      * @since 1.8
   766      * @since 1.8
   754      */
   767      */
   755     @Override
   768     @Override
   756     default Spliterator<E> spliterator() {
   769     default Spliterator<E> spliterator() {
   757         return Spliterators.spliterator(this, Spliterator.ORDERED);
   770         if (this instanceof RandomAccess) {
       
   771             return new AbstractList.RandomAccessSpliterator<>(this);
       
   772         } else {
       
   773             return Spliterators.spliterator(this, Spliterator.ORDERED);
       
   774         }
   758     }
   775     }
   759 
   776 
   760     /**
   777     /**
   761      * Returns an immutable list containing zero elements.
   778      * Returns an immutable list containing zero elements.
   762      *
   779      *