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

@ -448,8 +448,9 @@ public interface Set<E> extends Collection<E> {
*
* @since 9
*/
@SuppressWarnings("unchecked")
static <E> Set<E> of() {
return ImmutableCollections.emptySet();
return (Set<E>) ImmutableCollections.SetN.EMPTY_SET;
}
/**
@ -692,7 +693,9 @@ 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.emptySet();
@SuppressWarnings("unchecked")
var set = (Set<E>) ImmutableCollections.SetN.EMPTY_SET;
return set;
case 1:
return new ImmutableCollections.Set12<>(elements[0]);
case 2: