8193128: Reduce number of implementation classes returned by List/Set/Map.of()

8191418: List.of().indexOf(null) doesn't throw NullPointerException

Reviewed-by: smarks, jrose, martin, plevart
This commit is contained in:
Claes Redestad 2017-12-09 03:33:39 +01:00
parent a2ea38d2c9
commit 9aff9cb645
9 changed files with 510 additions and 274 deletions

View file

@ -449,7 +449,7 @@ public interface Set<E> extends Collection<E> {
* @since 9
*/
static <E> Set<E> of() {
return ImmutableCollections.Set0.instance();
return ImmutableCollections.emptySet();
}
/**
@ -464,7 +464,7 @@ public interface Set<E> extends Collection<E> {
* @since 9
*/
static <E> Set<E> of(E e1) {
return new ImmutableCollections.Set1<>(e1);
return new ImmutableCollections.Set12<>(e1);
}
/**
@ -481,7 +481,7 @@ public interface Set<E> extends Collection<E> {
* @since 9
*/
static <E> Set<E> of(E e1, E e2) {
return new ImmutableCollections.Set2<>(e1, e2);
return new ImmutableCollections.Set12<>(e1, e2);
}
/**
@ -692,11 +692,11 @@ public interface Set<E> extends Collection<E> {
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);
}