fungetBookInfo(): Book { return Book("Kotlin入门", 66.6f) }
dataclassBook(var name: String, var price: Float)
Kotlin 中数组,list、map系列集合默认也支持解构声明的功能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
funmain(args: Array<String>) { val array = arrayOf(1, 2, 3) val (a1, a2, a3) = array println("$a1") println("$a2") println("$a3") val list = listOf(1, 2, 3) val (b1, b2, b3) = list println("$b1") println("$b2") println("$b3") val map = mapOf("key1" to 1, "key2" to 2, "key3" to 3) for ((key, value) in map) { println("$key-$value") } }