< prev index next >

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

Print this page

        

@@ -446,13 +446,12 @@
      * @param <E> the {@code Set}'s element type
      * @return an empty {@code Set}
      *
      * @since 9
      */
-    @SuppressWarnings("unchecked")
     static <E> Set<E> of() {
-        return (Set<E>) ImmutableCollections.SetN.EMPTY_SET;
+        return ImmutableCollections.emptySet();
     }
 
     /**
      * Returns an unmodifiable set containing one element.
      * See <a href="#unmodifiable">Unmodifiable Sets</a> for details.

@@ -691,13 +690,11 @@
     @SafeVarargs
     @SuppressWarnings("varargs")
     static <E> Set<E> of(E... elements) {
         switch (elements.length) { // implicit null check of elements
             case 0:
-                @SuppressWarnings("unchecked")
-                var set = (Set<E>) ImmutableCollections.SetN.EMPTY_SET;
-                return set;
+                return ImmutableCollections.emptySet();
             case 1:
                 return new ImmutableCollections.Set12<>(elements[0]);
             case 2:
                 return new ImmutableCollections.Set12<>(elements[0], elements[1]);
             default:
< prev index next >