mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8221981: Simplify Map/List/Set.of() implementation
Reviewed-by: smarks
This commit is contained in:
parent
3233a6f944
commit
15d989faa4
4 changed files with 16 additions and 22 deletions
|
@ -787,8 +787,9 @@ public interface List<E> extends Collection<E> {
|
|||
*
|
||||
* @since 9
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
static <E> List<E> of() {
|
||||
return ImmutableCollections.emptyList();
|
||||
return (List<E>) ImmutableCollections.ListN.EMPTY_LIST;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1031,7 +1032,9 @@ 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.emptyList();
|
||||
@SuppressWarnings("unchecked")
|
||||
var list = (List<E>) ImmutableCollections.ListN.EMPTY_LIST;
|
||||
return list;
|
||||
case 1:
|
||||
return new ImmutableCollections.List12<>(elements[0]);
|
||||
case 2:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue