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

Add Arrays.asUnmodifiableList

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • core-libs
    • None

      Add an Arrays.asUnmodifiableList() API. This is similar to Arrays.asList(), which returns a List that wraps an array. The difference is that, unlike Arrays.asList, the new API will return an unmodifiable List.

      It should probably be a varargs method, like Arrays.asList. However the retrofit of varargs onto Arrays.asList was something of a problem (it seems to cause some ambiguities -- need to check this) so we might reconsider this.

      The implementation will probably need to be a new class that overrides all the mutator methods so as to provide strict UnsupportedOperationException throwing. It should avoid the problems with things like `Collections.singleton("abc").remove(123)` which is a no-op instead of throwing UOE. Care should be taken to ensure the views (sublist, reversed) are also strictly unmodifiable.

            kbourril kevin bourrillion
            smarks Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: