apply 与 with
apply返回他自己,with返回最后一行
fun main() {
val list = mutableListOf(1, 2, 3, 4, 5, 6)
println(list.apply {
this.add(111)
111
}) //apply:返回被设置后的它自己
println(with(list) {
this.add(222)
222
}) //apply:返回被设置后的最后一行
println(list) //[1, 2, 3, 4, 5, 6, 111, 222]
}
输出结果
let 与 run
also
有时间补上