NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
### `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 } ```