KT-42589 Add listOf, setOf, mapOf overloads for a single value to common src-set
`listOf`, `setOf` and `mapOf` overloads were defined in some source-sets but common source-set was missing it. This change adds common definition of these methods and also add declarations for source-sets that were previously missing it. ^KT-42589 fixed
This commit is contained in:
committed by
Space Team
parent
aa85e6d95c
commit
50841e7cb0
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -76,6 +76,16 @@ public fun <T> emptyList(): List<T> = EmptyList
|
||||
*/
|
||||
public fun <T> listOf(vararg elements: T): List<T> = if (elements.size > 0) elements.asList() else emptyList()
|
||||
|
||||
/**
|
||||
* Returns a new read-only list containing only the specified object [element].
|
||||
*
|
||||
* The returned list is serializable (JVM).
|
||||
*
|
||||
* @sample samples.collections.Collections.Lists.singletonReadOnlyList
|
||||
*/
|
||||
@SinceKotlin("1.9")
|
||||
public expect fun <T> listOf(element: T): List<T>
|
||||
|
||||
/**
|
||||
* Returns an empty read-only list. The returned list is serializable (JVM).
|
||||
* @sample samples.collections.Collections.Lists.emptyReadOnlyList
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -54,6 +54,17 @@ public fun <K, V> emptyMap(): Map<K, V> = @Suppress("UNCHECKED_CAST") (EmptyMap
|
||||
public fun <K, V> mapOf(vararg pairs: Pair<K, V>): Map<K, V> =
|
||||
if (pairs.size > 0) pairs.toMap(LinkedHashMap(mapCapacity(pairs.size))) else emptyMap()
|
||||
|
||||
/**
|
||||
* Returns a new read-only map, mapping only the specified key to the
|
||||
* specified value.
|
||||
*
|
||||
* The returned map is serializable (JVM).
|
||||
*
|
||||
* @sample samples.collections.Maps.Instantiation.mapFromPairs
|
||||
*/
|
||||
@SinceKotlin("1.9")
|
||||
public expect fun <K, V> mapOf(pair: Pair<K, V>): Map<K, V>
|
||||
|
||||
/**
|
||||
* Returns an empty read-only map.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -43,6 +43,16 @@ public fun <T> emptySet(): Set<T> = EmptySet
|
||||
*/
|
||||
public fun <T> setOf(vararg elements: T): Set<T> = if (elements.size > 0) elements.toSet() else emptySet()
|
||||
|
||||
/**
|
||||
* Returns a new read-only set containing only the specified object [element].
|
||||
*
|
||||
* The returned set is serializable (JVM).
|
||||
*
|
||||
* @sample samples.collections.Collections.Sets.singletonReadOnlySet
|
||||
*/
|
||||
@SinceKotlin("1.9")
|
||||
public expect fun <T> setOf(element: T): Set<T>
|
||||
|
||||
/**
|
||||
* Returns an empty read-only set. The returned set is serializable (JVM).
|
||||
* @sample samples.collections.Collections.Sets.emptyReadOnlySet
|
||||
|
||||
Reference in New Issue
Block a user