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
|
@ -1286,8 +1286,9 @@ public interface Map<K, V> {
|
|||
*
|
||||
* @since 9
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
static <K, V> Map<K, V> of() {
|
||||
return ImmutableCollections.emptyMap();
|
||||
return (Map<K,V>) ImmutableCollections.MapN.EMPTY_MAP;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1604,7 +1605,9 @@ public interface Map<K, V> {
|
|||
@SuppressWarnings("varargs")
|
||||
static <K, V> Map<K, V> ofEntries(Entry<? extends K, ? extends V>... entries) {
|
||||
if (entries.length == 0) { // implicit null check of entries array
|
||||
return ImmutableCollections.emptyMap();
|
||||
@SuppressWarnings("unchecked")
|
||||
var map = (Map<K,V>) ImmutableCollections.MapN.EMPTY_MAP;
|
||||
return map;
|
||||
} else if (entries.length == 1) {
|
||||
// implicit null check of the array slot
|
||||
return new ImmutableCollections.Map1<>(entries[0].getKey(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue