mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +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
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue