8221981: Simplify Map/List/Set.of() implementation

Reviewed-by: smarks
This commit is contained in:
Claes Redestad 2019-04-04 23:21:24 +02:00
parent 3233a6f944
commit 15d989faa4
4 changed files with 16 additions and 22 deletions

View file

@ -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: