[英]How can i declare list with values in single line in kotlin?
How can i declare a list in single line? 如何在单行中声明列表? In groovy i can do something like below
在groovy中我可以做下面的事情
def l = ['a', 'b', 'c'];
What is the kotlin equivalent for this? kotlin等效于什么?
You can easily find it in Kotlin documentation : 您可以在Kotlin 文档中轻松找到它:
val list = listOf('a', 'b', 'c')
/** Returns a new read-only list of given elements.
* The returned list is serializable (JVM).
*/
public fun <T> listOf(vararg elements: T): List<T>
= if (elements.size > 0) elements.asList() else emptyList()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.