< prev index next >
src/java.base/share/classes/java/util/Set.java
Print this page
rev 48077 : 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
Reviewed-by: smarks
@@ -447,11 +447,11 @@
* @return an empty {@code Set}
*
* @since 9
*/
static <E> Set<E> of() {
- return ImmutableCollections.Set0.instance();
+ return ImmutableCollections.emptySet();
}
/**
* Returns an unmodifiable set containing one element.
* See <a href="#unmodifiable">Unmodifiable Sets</a> for details.
@@ -462,11 +462,11 @@
* @throws NullPointerException if the element is {@code null}
*
* @since 9
*/
static <E> Set<E> of(E e1) {
- return new ImmutableCollections.Set1<>(e1);
+ return new ImmutableCollections.Set12<>(e1);
}
/**
* Returns an unmodifiable set containing two elements.
* See <a href="#unmodifiable">Unmodifiable Sets</a> for details.
@@ -479,11 +479,11 @@
* @throws NullPointerException if an element is {@code null}
*
* @since 9
*/
static <E> Set<E> of(E e1, E e2) {
- return new ImmutableCollections.Set2<>(e1, e2);
+ return new ImmutableCollections.Set12<>(e1, e2);
}
/**
* Returns an unmodifiable set containing three elements.
* See <a href="#unmodifiable">Unmodifiable Sets</a> for details.
@@ -690,15 +690,15 @@
@SafeVarargs
@SuppressWarnings("varargs")
static <E> Set<E> of(E... elements) {
switch (elements.length) { // implicit null check of elements
case 0:
- return ImmutableCollections.Set0.instance();
+ return ImmutableCollections.emptySet();
case 1:
- return new ImmutableCollections.Set1<>(elements[0]);
+ return new ImmutableCollections.Set12<>(elements[0]);
case 2:
- return new ImmutableCollections.Set2<>(elements[0], elements[1]);
+ return new ImmutableCollections.Set12<>(elements[0], elements[1]);
default:
return new ImmutableCollections.SetN<>(elements);
}
}
< prev index next >