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

Add static convenience methods on List/Set/Map

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8
    • Fix Version/s: tbd_major
    • Component/s: core-libs
    • Labels:
      None

      Description

      Per Stephen Colebourne: (http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-June/018423.html)

      One point lambdaification that I haven't seen mentioned is addition
      static factory methods for the main collection interfaces. (Strictly,
      this proposal is not point lambdaification as it does not involve
      lambdas, but it is very much in the same area).

      I propose adding these static methods:
      Collection.empty()
      Collection.of(T...)
      List.empty()
      List.of(T...)
      Set.empty()
      Set.of(T...)
      Map.empty()
      Map.of(Entry...)
      Map.Entry.of(K, V)

      Each of these methods would return immutable implementations.
      There is a case for extending the methods to Iterator and other
      collection types, however these are the most important.
      These follow the designs of Stream static methods IIRC.

      This library change would remove much of the requirement for the
      "collection literals" change discussed in Project Coin.

      Implementation would ideally be via new dedicated immutable classes,
      however space could be saved by simply reusing the existing classes.

      Is this something we could fit in? (Is resourcing the problem, or the idea?)

      thanks
      Stephen

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              smarks Stuart Marks
              Reporter:
              mduigou Mike Duigou
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: