mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
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:
parent
a2ea38d2c9
commit
9aff9cb645
9 changed files with 510 additions and 274 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue