< prev index next >

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

Print this page

        

@@ -785,13 +785,12 @@
      * @param <E> the {@code List}'s element type
      * @return an empty {@code List}
      *
      * @since 9
      */
-    @SuppressWarnings("unchecked")
     static <E> List<E> of() {
-        return (List<E>) ImmutableCollections.ListN.EMPTY_LIST;
+        return ImmutableCollections.emptyList();
     }
 
     /**
      * Returns an unmodifiable list containing one element.
      *

@@ -1030,13 +1029,11 @@
     @SafeVarargs
     @SuppressWarnings("varargs")
     static <E> List<E> of(E... elements) {
         switch (elements.length) { // implicit null check of elements
             case 0:
-                @SuppressWarnings("unchecked")
-                var list = (List<E>) ImmutableCollections.ListN.EMPTY_LIST;
-                return list;
+                return ImmutableCollections.emptyList();
             case 1:
                 return new ImmutableCollections.List12<>(elements[0]);
             case 2:
                 return new ImmutableCollections.List12<>(elements[0], elements[1]);
             default:
< prev index next >