多应用+插件架构,代码干净,支持一键云编译,码云点赞13K star,4.8-4.12 预售价格198元 广告
### `also` **上下文对象**作为 lambda 表达式的参数(`it`)来访问。 **返回值**是上下文对象本身。 `also` 对于执行一些将上下文对象作为参数的操作很有用。 Use `also` for actions that need a reference rather to the object than to its properties and functions, or when you don't want to shadow `this` reference from an outer scope. 当你在代码中看到 `also` 时,可以将其理解为“*并且用该对象执行以下操作*”。 ```kotlin fun main() { //sampleStart val numbers = mutableListOf("one", "two", "three") numbers .also { println("The list elements before adding new one: $it") } .add("four") //sampleEnd } ```