ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
### `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 } ```