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

'Map.of' methods should return SequencedMap

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • None
    • core-libs

      ADDITIONAL SYSTEM INFORMATION :
      Microsoft Windows [Version 10.0.26100.6725]
      (c) Microsoft Corporation. All rights reserved.

      C:\Users\hwaite>%JAVA_HOME%\bin\java -version
      openjdk version "25" 2025-09-16
      OpenJDK Runtime Environment (build 25+36-3489)
      OpenJDK 64-Bit Server VM (build 25+36-3489, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      The 'Map.of' methods currently return a Map. These methods would be more convenient if they returned SequencedMap instead (or at least a regular Map that happens to maintain order). This overloaded method accepts a maximum of 10 key/value pairs. As such, the performance implications of retaining order are insignificant. However, when a developer needs to preserve ordering, there's a significant verbosity penalty. One needs to declare a LinkedHashMap and wrap it in an unmodifiable map.

      There should be minimal backwards compatibility issues, since SequencedMap is a subinterface of Map. This proposal is an alternative to adding 'SequencedMap.of' methods (JDK-8323729).


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

              Created:
              Updated:
              Resolved: