Calls the specified function [block] with `this` value as its receiver and returns `this` value. For detailed usage information see the documentation for [scope functions] (https://kotlinlang.org/docs/reference/scope-functions.html#apply). @kotlin.internal.InlineOnly public inline fun <T> T....
run函数类似于apply函数,但是run函数返回的是最后一行的值。 /** * Calls the specified function [block] with `this` value as its receiver and returns its result. */@kotlin.internal.InlineOnlypublic inline fun T.run(block: T.() -> R): R { contract { callsInPlace(block, InvocationKind.EXA...
* Calls the specified function [block] with `this` value * as its receiver and returns `this` value. * 以' this '值作为接收者调用指定函数[block],并返回' this '值。 * * For detailed usage information see the documentation for [scope functions] * (https://kotlinlang.org/docs/reference...
InvocationKind.EXACTLY_ONCE)4}5block()6returnthis7}89/**10* Calls the specified function [block] with `this` value as its argument and returns `this` value.11*12* For detailed usage information see the documentation for [scope functions](https://kotlinlang.org/docs/reference/scope-...
1、普通函数 VS 扩展函数 (Normal vs. extension function)如果我们对比 with 和T.run 这两个函数的话,他们实际上是十分相似的。下面使用他们实现相同的功能的例子.with(webview.settings) { javaScriptEnabled = true databaseEnabled = true } // similarly webview.settings.run { javaScriptEnabled = true ...
这玩意叫 “Kotlin Function Literals with Receiver” ,是不是还有点懵逼?让我们将概念化繁为简,其直接翻译为:带接收器的函数字面量。由于Lambda是一种函数字面量,所以其可以进一步具体化为:带接收器的Lambda表达式。 例如有如下Lambda val greet1:()->Unit= { println("hello world")} 我们可以为上面的...
( 参数和返回值为函数的函数 )Calls the specified function [block] with `this` value as its receiver and returns `this` value.For detailed usage information see the documentation for [scope functions](https://kotlinlang.org/docs/reference/scope-functions.html#apply).@kotlin.internal.InlineOnly...
6. Using theonEach()Function Next to theforEach()function, Kotlin provides theonEach()function. Let’s first look at its implementation: public inline fun <T, C : Iterable<T>> C.onEach(action: (T) -> Unit): C { return apply { for (element in this) action(element) } ...
/** * Calls the specified function [block] with `this` value * as its receiver and returns `this` value. * 以' this '值作为接收者调用指定函数[block],并返回' this '值。 * * For detailed usage information see the documentation for [scope functions] * (https://kotlinlang.org/docs/ref...
* @description:Kotlin常见的高阶函数 */fun main(args:Array<String>) {/** * Calls the specified function [block] with `this` value as its receiver and returns `this` value. *//*@kotlin.internal.InlineOnly public inline fun <T> T.apply(block: T.() -> Unit): T { ...