--- old/src/java.base/share/classes/java/util/List.java 2017-09-20 16:53:08.000000000 -0700
+++ new/src/java.base/share/classes/java/util/List.java 2017-09-20 16:53:08.000000000 -0700
@@ -87,15 +87,16 @@
* Such exceptions are marked as "optional" in the specification for this
* interface.
*
- *
- * The {@link List#of(Object...) List.of()} static factory methods
- * provide a convenient way to create immutable lists. The {@code List}
+ *
+ * The {@link List#of(Object...) List.of} and
+ * {@link List#copyOf List.copyOf} static factory methods
+ * provide a convenient way to create unmodifiable lists. The {@code List}
* instances created by these methods have the following characteristics:
*
*
- * - They are structurally immutable. Elements cannot be added, removed,
- * or replaced. Calling any mutator method will always cause
- * {@code UnsupportedOperationException} to be thrown.
+ *
- They are unmodifiable. Elements cannot
+ * be added, removed, or replaced. Calling any mutator method on the List
+ * will always cause {@code UnsupportedOperationException} to be thrown.
* However, if the contained elements are themselves mutable,
* this may cause the List's contents to appear to change.
*
- They disallow {@code null} elements. Attempts to create them with
@@ -776,9 +777,9 @@
}
/**
- * Returns an immutable list containing zero elements.
+ * Returns an unmodifiable list containing zero elements.
*
- * See Immutable List Static Factory Methods for details.
+ * See Unmodifiable Lists for details.
*
* @param the {@code List}'s element type
* @return an empty {@code List}
@@ -790,9 +791,9 @@
}
/**
- * Returns an immutable list containing one element.
+ * Returns an unmodifiable list containing one element.
*
- * See Immutable List Static Factory Methods for details.
+ * See Unmodifiable Lists for details.
*
* @param the {@code List}'s element type
* @param e1 the single element
@@ -806,9 +807,9 @@
}
/**
- * Returns an immutable list containing two elements.
+ * Returns an unmodifiable list containing two elements.
*
- * See Immutable List Static Factory Methods for details.
+ * See Unmodifiable Lists for details.
*
* @param the {@code List}'s element type
* @param e1 the first element
@@ -823,9 +824,9 @@
}
/**
- * Returns an immutable list containing three elements.
+ * Returns an unmodifiable list containing three elements.
*
- * See Immutable List Static Factory Methods for details.
+ * See Unmodifiable Lists for details.
*
* @param the {@code List}'s element type
* @param e1 the first element
@@ -841,9 +842,9 @@
}
/**
- * Returns an immutable list containing four elements.
+ * Returns an unmodifiable list containing four elements.
*
- * See Immutable List Static Factory Methods for details.
+ * See Unmodifiable Lists for details.
*
* @param the {@code List}'s element type
* @param e1 the first element
@@ -860,9 +861,9 @@
}
/**
- * Returns an immutable list containing five elements.
+ * Returns an unmodifiable list containing five elements.
*
- * See Immutable List Static Factory Methods for details.
+ * See Unmodifiable Lists for details.
*
* @param the {@code List}'s element type
* @param e1 the first element
@@ -880,9 +881,9 @@
}
/**
- * Returns an immutable list containing six elements.
+ * Returns an unmodifiable list containing six elements.
*
- * See Immutable List Static Factory Methods for details.
+ * See Unmodifiable Lists for details.
*
* @param the {@code List}'s element type
* @param e1 the first element
@@ -902,9 +903,9 @@
}
/**
- * Returns an immutable list containing seven elements.
+ * Returns an unmodifiable list containing seven elements.
*
- * See Immutable List Static Factory Methods for details.
+ * See Unmodifiable Lists for details.
*
* @param the {@code List}'s element type
* @param e1 the first element
@@ -925,9 +926,9 @@
}
/**
- * Returns an immutable list containing eight elements.
+ * Returns an unmodifiable list containing eight elements.
*
- * See Immutable List Static Factory Methods for details.
+ * See Unmodifiable Lists for details.
*
* @param the {@code List}'s element type
* @param e1 the first element
@@ -949,9 +950,9 @@
}
/**
- * Returns an immutable list containing nine elements.
+ * Returns an unmodifiable list containing nine elements.
*
- * See Immutable List Static Factory Methods for details.
+ * See Unmodifiable Lists for details.
*
* @param the {@code List}'s element type
* @param e1 the first element
@@ -974,9 +975,9 @@
}
/**
- * Returns an immutable list containing ten elements.
+ * Returns an unmodifiable list containing ten elements.
*
- * See Immutable List Static Factory Methods for details.
+ * See Unmodifiable Lists for details.
*
* @param the {@code List}'s element type
* @param e1 the first element
@@ -1000,8 +1001,8 @@
}
/**
- * Returns an immutable list containing an arbitrary number of elements.
- * See Immutable List Static Factory Methods for details.
+ * Returns an unmodifiable list containing an arbitrary number of elements.
+ * See Unmodifiable Lists for details.
*
* @apiNote
* This method also accepts a single array as an argument. The element type of
@@ -1038,4 +1039,23 @@
return new ImmutableCollections.ListN<>(elements);
}
}
+
+ /**
+ * Returns an unmodifiable List containing the elements of the given Collection,
+ * in iteration order. See Unmodifiable Lists for
+ * information about the characteristics of the returned List.
+ *
+ * @param the {@code List}'s element type
+ * @param coll the collection from which elements are drawn
+ * @return the new List
+ * @since 10
+ */
+ @SuppressWarnings("unchecked")
+ static List copyOf(Collection extends E> coll) {
+ if (coll instanceof ImmutableCollections.AbstractImmutableList) {
+ return (List)coll;
+ } else {
+ return (List)List.of(coll.toArray());
+ }
+ }
}