val myStr: String = "AAA"//扩展属性val String.myInfo: String get() = "yuknight"fun String.showPrintln(): String { println("打印输出,并链式调用,内容是:$this") return this}val String.strValue: String get() = "当前${System.currentTimeMillis()},调用一次,值是:$this,长度是$length"//对 String?==可空类型的进行函数扩展fun String?.outputStrValueF(defaultValue:String) = println(this ?: defaultValue)fun String?.outputStrValueFget(defaultValue: String) = if (this == null) defaultValue else thisfun main(){ val str:String = "ABC" println(str.myInfo) //扩展函数 str.showPrintln().showPrintln().showPrintln() //扩展属性 str.myInfo.showPrintln().showPrintln() "yuknight".strValue.showPrintln().showPrintln() val infoValue:String? = null //infoValue是可空类型 String String?==可空类型 infoValue.outputStrValueF("默认值1") val name = "yuknight" name.outputStrValueFget("默认值2") println(infoValue.outputStrValueFget("默认值3")) println(name.outputStrValueFget("默认值4"))}