义:** * 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) {
//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.with(that: B): Pair = Pair(this, that)