在 Kotlin 中是否可以像在 Python 中那样进行参数解包?例如
>>> a = [1,2,3]
>>> b = [*a,4,5,6]
>>> b
[1, 2, 3, 4, 5, 6]
我知道在 Kotlin 中可以这样做:
>>> listOf(1, 2, 3, *listOf(4,5,6).toTypedArray())
[1, 2, 3, 4, 5, 6]
感觉在 Kotlin 中有一种更简单的方法。有什么想法吗?
最佳答案
spread operator适用于数组,因此您可以这样做:
listOf(1, 2, 3, *(arrayOf(4, 5, 6)))
关于kotlin - 是否可以在 Kotlin 的列表中传播列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47927571/