< prev index next >

src/java.base/share/classes/java/util/List.java

Print this page
rev 48077 : 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
Reviewed-by: smarks

*** 786,796 **** * @return an empty {@code List} * * @since 9 */ static <E> List<E> of() { ! return ImmutableCollections.List0.instance(); } /** * Returns an unmodifiable list containing one element. * --- 786,796 ---- * @return an empty {@code List} * * @since 9 */ static <E> List<E> of() { ! return ImmutableCollections.AbstractImmutableList.emptyList(); } /** * Returns an unmodifiable list containing one element. *
*** 802,812 **** * @throws NullPointerException if the element is {@code null} * * @since 9 */ static <E> List<E> of(E e1) { ! return new ImmutableCollections.List1<>(e1); } /** * Returns an unmodifiable list containing two elements. * --- 802,812 ---- * @throws NullPointerException if the element is {@code null} * * @since 9 */ static <E> List<E> of(E e1) { ! return ImmutableCollections.AbstractImmutableList.of(e1); } /** * Returns an unmodifiable list containing two elements. *
*** 819,829 **** * @throws NullPointerException if an element is {@code null} * * @since 9 */ static <E> List<E> of(E e1, E e2) { ! return new ImmutableCollections.List2<>(e1, e2); } /** * Returns an unmodifiable list containing three elements. * --- 819,829 ---- * @throws NullPointerException if an element is {@code null} * * @since 9 */ static <E> List<E> of(E e1, E e2) { ! return ImmutableCollections.AbstractImmutableList.of(e1, e2); } /** * Returns an unmodifiable list containing three elements. *
*** 1027,1046 **** * @since 9 */ @SafeVarargs @SuppressWarnings("varargs") static <E> List<E> of(E... elements) { ! switch (elements.length) { // implicit null check of elements ! case 0: ! return ImmutableCollections.List0.instance(); ! case 1: ! return new ImmutableCollections.List1<>(elements[0]); ! case 2: ! return new ImmutableCollections.List2<>(elements[0], elements[1]); ! default: ! return new ImmutableCollections.ListN<>(elements); ! } } /** * Returns an <a href="#unmodifiable">unmodifiable List</a> containing the elements of * the given Collection, in its iteration order. The given Collection must not be null, --- 1027,1037 ---- * @since 9 */ @SafeVarargs @SuppressWarnings("varargs") static <E> List<E> of(E... elements) { ! return ImmutableCollections.AbstractImmutableList.of(elements); } /** * Returns an <a href="#unmodifiable">unmodifiable List</a> containing the elements of * the given Collection, in its iteration order. The given Collection must not be null,
< prev index next >