Update example for default buildList to not use capacity KT-41136 (#3688)
This commit is contained in:
@@ -9,6 +9,19 @@ class Builders {
|
|||||||
fun buildListSample() {
|
fun buildListSample() {
|
||||||
val x = listOf('b', 'c')
|
val x = listOf('b', 'c')
|
||||||
|
|
||||||
|
val y = buildList() {
|
||||||
|
add('a')
|
||||||
|
addAll(x)
|
||||||
|
add('d')
|
||||||
|
}
|
||||||
|
|
||||||
|
assertPrints(y, "[a, b, c, d]")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Sample
|
||||||
|
fun buildListSampleWithCapacity() {
|
||||||
|
val x = listOf('b', 'c')
|
||||||
|
|
||||||
val y = buildList(x.size + 2) {
|
val y = buildList(x.size + 2) {
|
||||||
add('a')
|
add('a')
|
||||||
addAll(x)
|
addAll(x)
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ internal expect inline fun <E> buildListInternal(builderAction: MutableList<E>.(
|
|||||||
*
|
*
|
||||||
* @throws IllegalArgumentException if the given [capacity] is negative.
|
* @throws IllegalArgumentException if the given [capacity] is negative.
|
||||||
*
|
*
|
||||||
* @sample samples.collections.Builders.Lists.buildListSample
|
* @sample samples.collections.Builders.Lists.buildListSampleWithCapacity
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
@ExperimentalStdlibApi
|
@ExperimentalStdlibApi
|
||||||
|
|||||||
Reference in New Issue
Block a user