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
|
@ -788,7 +788,7 @@ public interface List<E> extends Collection<E> {
|
|||
* @since 9
|
||||
*/
|
||||
static <E> List<E> of() {
|
||||
return ImmutableCollections.List0.instance();
|
||||
return ImmutableCollections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -804,7 +804,7 @@ public interface List<E> extends Collection<E> {
|
|||
* @since 9
|
||||
*/
|
||||
static <E> List<E> of(E e1) {
|
||||
return new ImmutableCollections.List1<>(e1);
|
||||
return new ImmutableCollections.List12<>(e1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -821,7 +821,7 @@ public interface List<E> extends Collection<E> {
|
|||
* @since 9
|
||||
*/
|
||||
static <E> List<E> of(E e1, E e2) {
|
||||
return new ImmutableCollections.List2<>(e1, e2);
|
||||
return new ImmutableCollections.List12<>(e1, e2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1031,11 +1031,11 @@ public interface List<E> extends Collection<E> {
|
|||
static <E> List<E> of(E... elements) {
|
||||
switch (elements.length) { // implicit null check of elements
|
||||
case 0:
|
||||
return ImmutableCollections.List0.instance();
|
||||
return ImmutableCollections.emptyList();
|
||||
case 1:
|
||||
return new ImmutableCollections.List1<>(elements[0]);
|
||||
return new ImmutableCollections.List12<>(elements[0]);
|
||||
case 2:
|
||||
return new ImmutableCollections.List2<>(elements[0], elements[1]);
|
||||
return new ImmutableCollections.List12<>(elements[0], elements[1]);
|
||||
default:
|
||||
return new ImmutableCollections.ListN<>(elements);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue