package com.dongnao.lsn1
/**
* Created by xiang on 2017/5/26.
*/
fun test(i: Int = 100, j: String = "") {
}
fun test(j: String = "") {
val i = 100
}
//可变参数
fun test(vararg item: Int) {
item.forEach { }
}
inline fun String.show() {
}
inline val String.lastChar: Char
get() = get(length - 1)
fun main(args: Array<String>) {
//list集合
val list = listOf(1, 2, 3, 4)
list[0]
list.last()
//遍历集合
for (i in list) {
}
list.forEach {
item ->
println(item)
}
list.forEachIndexed { index, i -> }
list.joinToString()
//默认参数函数调用
test()
test(1)
test(1, "11")
test(j = "22")
//可变长度参数
test(1, 2, 3, 4, 5, 6, 7)
//扩展方法
"".show()
//map映射集合
val map = mapOf(1 to "a", 2 to "b", "c" to 1)
//获取对应key元素
map[1]
map["c"]
//中缀调用 infix
1 to "a"
1.to("a")
//中缀方法
1 with "a"
//析构声明
val pair = "a" to "b"
val (key, value) = pair
val compile = "com.android.support.constraint:constraint-layout:1.0.2"
val (group, name, version) = compile.split(":")
}
infix fun <A, B> A.with(that: B): Pair<A, B> = Pair(this, that)
共同学习,写下你的评论
评论加载中...
作者其他优质文章