Details

    • Type: Sub-task
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:

      Description

      Explore the potential uses of convenience Factory Methods for Collections (List.of(), Map.ofEntries(), etc) within the JDK.

      There are probably places in the JDK where collections are created and initialized with contents and are thereafter not changed. They're effectively immutable. They might or might not be wrapped with the unmodiable wrappers. But, searching for calls to Collections.unmodifiable*() might prove fruitful at turning up locations where the convenience factories could be used.

      There are probably a bunch of places where lists are initialized using Arrays.asList(). It might be reasonable to look for these locations and to investigate replacing them with calls to List.of().

      Bear in mind that the immutable collections returned by the convenience factories have different semantics from collections wrapped with the unmodifiable wrappers. One is that the original collections are still modifiable by anyone who keeps a reference to them. Another is that the iteration order of the new sets and maps differs (in fact, the iteration order changes randomly).

      The List returned by Arrays.asList() is actually mutable, but it cannot change size (i.e., no adds or removes are permitted). However, the List returned by List.of() is truly immutable. In addition, calling List.of() unavoidably creates a copy of its input array, for sizes larger than 2, which may be a performance concern.

      These issues represent potential incompatibilities and must be investigated or tested. Therefore, while the convenience factories are probably useful in many cases, they aren't necessarily a drop-in replacement for Collections.unmodifiable*(...) and Arrays.asList().

        Attachments

          Activity

            People

            • Assignee:
              smarks Stuart Marks
              Reporter:
              smarks Stuart Marks
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: