(更新中。。。)
apply和also 返回引用者本身
let和run 返回最后一行
var str : String = "abc"
fun testApply(){
println("Apply")
var str0 = str.apply {
this.toUpperCase()
println(this)
}
println(str0)
}
fun testAlso(){
println("also")
var str0 = str.also {
it.toUpperCase()
println(it)
}
println(str0)
}
fun testLet(){
println("let")
var str0 = str.let {
it.toUpperCase()
println(it)
Unit
}
println(str0)
}
fun testRun(){
println("run")
var str0 = str.run {
this.toUpperCase()
this.length
UInt
}
println(str0)
}
fun testWith(){
println("with")
with(str){
str = "1111"
}
}
网友评论