Kotlin destructuring

import java.util.*

fun main() {
    val res = "1,2,3,4,5"
    val list = res.split(",")
    //c++解构
    val (v1, v2, v3, v4, v5) = list;
    println("v1:$v1 v2:$v2 v3:$v3 v4:$v4")

}

Arrays can be destructured

objects can also

 val (name, price) = Book("Kotlin入门", 66.6f)

perfectly worked

It must be borrowed from the destructuring of c++

 

Guess you like

Origin blog.csdn.net/mp624183768/article/details/123618939