我可以说在科特林
//sweet
for ((key,value) in System.getProperties())
println("$key = $value")
Run Code Online (Sandbox Code Playgroud)
但我不能说
//sour
val properties = System.getProperties()
val list = properties.map((key,value) -> "$key = $value")
Run Code Online (Sandbox Code Playgroud)
什么是Scot中的Kotlin等价物properties.map{case (key, value) => s"$key = $value"}?
在Kotlin 1.0中你可以说:
val properties = System.getProperties()
val list = properties.map { "${it.key} = ${it.value}" }
Run Code Online (Sandbox Code Playgroud)
如果您希望将地图条目解压缩为单独的值,您可以说:
val properties = System.getProperties()
val list = properties.map { val (key, value) = it; "$key = $value" }
Run Code Online (Sandbox Code Playgroud)
在Kotlin 1.1中,您现在可以使用解构声明语法来解包传递给lambda的参数"(Kotlin 1.1中的新功能 - Kotlin编程语言):
val properties = System.getProperties()
val list = properties.map { (key,value) -> "$key = $value" }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1146 次 |
| 最近记录: |