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

List spec should state that unmodifiable lists implement RandomAccess

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 15
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      There are no implementation changes; all the implementations already implement the RandomAccess marker interface.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      The java.util.List specification should state that unmodifiable list instances will implement the RandomAccess marker interface.

      Problem

      In the "Unmodifiable Lists" section of the List class specification, there is a bulleted series of requirements on the instances returned by the List.of and related methods. These requirements inadvertently omitted the fact that such lists implement the RandomAccess marker interface.

      Solution

      Add an item to that section requiring that RandomAccess be implemented.

      Specification

      diff -r 46108b5b69d9 -r 45a22ec2df1a src/java.base/share/classes/java/util/List.java
      --- a/src/java.base/share/classes/java/util/List.java   Tue Apr 07 16:31:46 2020 -0700
      +++ b/src/java.base/share/classes/java/util/List.java   Thu Apr 09 19:47:27 2020 -0700
      @@ -104,6 +104,8 @@
        * <li>They are serializable if all elements are serializable.
        * <li>The order of elements in the list is the same as the order of the
        * provided arguments, or of the elements in the provided array.
      + * <li>The lists and their {@link #subList(int, int) subList} views implement the
      + * {@link RandomAccess} interface.
        * <li>They are <a href="../lang/doc-files/ValueBased.html">value-based</a>.
        * Callers should make no assumptions about the identity of the returned instances.
        * Factories are free to create new instances or reuse existing ones. Therefore,

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              smarks Stuart Marks
              Reporter:
              smarks Stuart Marks
              Reviewed By:
              Lance Andersen
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: